| Line | Source | Count |
| 1 | This file is fg_bg.def, from which is created fg_bg.c. | - |
| 2 | It implements the builtins "bg" and "fg" in Bash. | - |
| 3 | | - |
| 4 | Copyright (C) 1987-2009 Free Software Foundation, Inc. | - |
| 5 | | - |
| 6 | This file is part of GNU Bash, the Bourne Again SHell. | - |
| 7 | | - |
| 8 | Bash is free software: you can redistribute it and/or modify | - |
| 9 | it under the terms of the GNU General Public License as published by | - |
| 10 | the Free Software Foundation, either version 3 of the License, or | - |
| 11 | (at your option) any later version. | - |
| 12 | | - |
| 13 | Bash is distributed in the hope that it will be useful, | - |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | - |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | - |
| 16 | GNU General Public License for more details. | - |
| 17 | | - |
| 18 | You should have received a copy of the GNU General Public License | - |
| 19 | along with Bash. If not, see <http: | - |
| 20 | | - |
| 21 | $PRODUCES fg_bg.c | - |
| 22 | | - |
| 23 | $BUILTIN fg | - |
| 24 | $FUNCTION fg_builtin | - |
| 25 | $DEPENDS_ON JOB_CONTROL | - |
| 26 | $SHORT_DOC fg [job_spec] | - |
| 27 | Move job to the foreground. | - |
| 28 | | - |
| 29 | Place the job identified by JOB_SPEC in the foreground, making it the | - |
| 30 | current job. If JOB_SPEC is not present, the shell's notion of the | - |
| 31 | current job is used. | - |
| 32 | | - |
| 33 | Exit Status: | - |
| 34 | Status of command placed in foreground, or failure if an error occurs. | - |
| 35 | $END | - |
| 36 | | - |
| 37 | #include <config.h> | - |
| 38 | | - |
| 39 | #include "../bashtypes.h" | - |
| 40 | #include <signal.h> | - |
| 41 | | - |
| 42 | #if defined (HAVE_UNISTD_H) | - |
| 43 | # include <unistd.h> | - |
| 44 | #endif | - |
| 45 | | - |
| 46 | #include "../bashintl.h" | - |
| 47 | | - |
| 48 | #include "../shell.h" | - |
| 49 | #include "../execute_cmd.h" | - |
| 50 | #include "../jobs.h" | - |
| 51 | #include "common.h" | - |
| 52 | #include "bashgetopt.h" | - |
| 53 | | - |
| 54 | #if defined (JOB_CONTROL) | - |
| 55 | static int fg_bg __P((WORD_LIST *, int)); | - |
| 56 | | - |
| 57 | | - |
| 58 | int | - |
| 59 | fg_builtin (list) | - |
| 60 | WORD_LIST *list; | - |
| 61 | { | - |
| 62 | int fg_bit; | - |
| 63 | register WORD_LIST *t; | - |
| 64 | | - |
| 65 | CHECK_HELPOPT (list); never executed: __result = (((const unsigned char *) (const char *) ( ((list)->word->word) ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( "--help" ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: return (258); | TRUE | evaluated 23 times by 1 test | | FALSE | evaluated 1 time by 1 test |
| TRUE | evaluated 23 times by 1 test | | FALSE | never evaluated |
| TRUE | evaluated 3 times by 1 test | | FALSE | evaluated 20 times by 1 test |
| TRUE | never evaluated | | FALSE | evaluated 3 times by 1 test |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-23 |
| 66 | | - |
| 67 | if (job_control == 0)| TRUE | evaluated 4 times by 1 test | | FALSE | evaluated 20 times by 1 test |
| 4-20 |
| 68 | { | - |
| 69 | sh_nojobs ((char *)NULL); | - |
| 70 | return (EXECUTION_FAILURE);executed 4 times by 1 test: return (1); | 4 |
| 71 | } | - |
| 72 | | - |
| 73 | if (no_options (list))| TRUE | evaluated 3 times by 1 test | | FALSE | evaluated 17 times by 1 test |
| 3-17 |
| 74 | return (EX_USAGE);executed 3 times by 1 test: return (258); | 3 |
| 75 | list = loptend; | - |
| 76 | | - |
| 77 | | - |
| 78 | | - |
| 79 | for (t = list; t && t->next; t = t->next)| TRUE | evaluated 17 times by 1 test | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | evaluated 17 times by 1 test |
| 0-17 |
| 80 | ; never executed: ; | 0 |
| 81 | fg_bit = (t && t->word->word[0] == '&' && t->word->word[1] == '\0') == 0;| TRUE | evaluated 17 times by 1 test | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | evaluated 17 times by 1 test |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-17 |
| 82 | | - |
| 83 | return (fg_bg (list, fg_bit));executed 17 times by 1 test: return (fg_bg (list, fg_bit)); | 17 |
| 84 | } | - |
| 85 | #endif /* JOB_CONTROL */ | - |
| 86 | | - |
| 87 | $BUILTIN bg | - |
| 88 | $FUNCTION bg_builtin | - |
| 89 | $DEPENDS_ON JOB_CONTROL | - |
| 90 | $SHORT_DOC bg [job_spec ...] | - |
| 91 | Move jobs to the background. | - |
| 92 | | - |
| 93 | Place the jobs identified by each JOB_SPEC in the background, as if they | - |
| 94 | had been started with `&'. If JOB_SPEC is not present, the shells notion | - |
| 95 | of the current job is used. | - |
| 96 | | - |
| 97 | Exit Status: | - |
| 98 | Returns success unless job control is not enabled or an error occurs. | - |
| 99 | $END | - |
| 100 | | - |
| 101 | #if defined (JOB_CONTROL) | - |
| 102 | | - |
| 103 | int | - |
| 104 | bg_builtin (list) | - |
| 105 | WORD_LIST *list; | - |
| 106 | { | - |
| 107 | int r; | - |
| 108 | | - |
| 109 | CHECK_HELPOPT (list); never executed: __result = (((const unsigned char *) (const char *) ( ((list)->word->word) ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: __result = (((const unsigned char *) (const char *) ( "--help" ))[3] - __s2[3]); never executed: end of block never executed: end of block never executed: return (258); | TRUE | evaluated 7 times by 1 test | | FALSE | evaluated 1 time by 1 test |
| TRUE | evaluated 7 times by 1 test | | FALSE | never evaluated |
| TRUE | evaluated 3 times by 1 test | | FALSE | evaluated 4 times by 1 test |
| TRUE | never evaluated | | FALSE | evaluated 3 times by 1 test |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| TRUE | never evaluated | | FALSE | never evaluated |
| 0-7 |
| 110 | | - |
| 111 | if (job_control == 0)| TRUE | evaluated 1 time by 1 test | | FALSE | evaluated 7 times by 1 test |
| 1-7 |
| 112 | { | - |
| 113 | sh_nojobs ((char *)NULL); | - |
| 114 | return (EXECUTION_FAILURE);executed 1 time by 1 test: return (1); | 1 |
| 115 | } | - |
| 116 | | - |
| 117 | if (no_options (list))| TRUE | evaluated 3 times by 1 test | | FALSE | evaluated 4 times by 1 test |
| 3-4 |
| 118 | return (EX_USAGE);executed 3 times by 1 test: return (258); | 3 |
| 119 | list = loptend; | - |
| 120 | | - |
| 121 | | - |
| 122 | | - |
| 123 | r = EXECUTION_SUCCESS; | - |
| 124 | do | - |
| 125 | { | - |
| 126 | if (fg_bg (list, 0) == EXECUTION_FAILURE)| TRUE | never evaluated | | FALSE | evaluated 4 times by 1 test |
| 0-4 |
| 127 | r = EXECUTION_FAILURE; never executed: r = 1; | 0 |
| 128 | if (list)| TRUE | evaluated 4 times by 1 test | | FALSE | never evaluated |
| 0-4 |
| 129 | list = list->next;executed 4 times by 1 test: list = list->next; | 4 |
| 130 | }executed 4 times by 1 test: end of block | 4 |
| 131 | while (list);| TRUE | never evaluated | | FALSE | evaluated 4 times by 1 test |
| 0-4 |
| 132 | | - |
| 133 | return r;executed 4 times by 1 test: return r; | 4 |
| 134 | } | - |
| 135 | | - |
| 136 | | - |
| 137 | static int | - |
| 138 | fg_bg (list, foreground) | - |
| 139 | WORD_LIST *list; | - |
| 140 | int foreground; | - |
| 141 | { | - |
| 142 | sigset_t set, oset; | - |
| 143 | int job, status, old_async_pid; | - |
| 144 | JOB *j; | - |
| 145 | | - |
| 146 | BLOCK_CHILD (set, oset); | - |
| 147 | job = get_job_spec (list); | - |
| 148 | | - |
| 149 | if (INVALID_JOB (job))| TRUE | never evaluated | | FALSE | evaluated 21 times by 1 test |
| TRUE | never evaluated | | FALSE | evaluated 21 times by 1 test |
| TRUE | evaluated 3 times by 1 test | | FALSE | evaluated 18 times by 1 test |
| 0-21 |
| 150 | { | - |
| 151 | if (job != DUP_JOB)| TRUE | evaluated 3 times by 1 test | | FALSE | never evaluated |
| 0-3 |
| 152 | sh_badjob (list ? list->word->word : _("current"));executed 3 times by 1 test: sh_badjob (list ? list->word->word : dcgettext (((void *)0), "current" , 5) ); | 3 |
| 153 | | - |
| 154 | goto failure;executed 3 times by 1 test: goto failure; | 3 |
| 155 | } | - |
| 156 | | - |
| 157 | j = get_job_by_jid (job); | - |
| 158 | | - |
| 159 | if (IS_JOBCONTROL (job) == 0)| TRUE | evaluated 1 time by 1 test | | FALSE | evaluated 17 times by 1 test |
| 1-17 |
| 160 | { | - |
| 161 | builtin_error (_("job %d started without job control"), job + 1); | - |
| 162 | goto failure;executed 1 time by 1 test: goto failure; | 1 |
| 163 | } | - |
| 164 | | - |
| 165 | if (foreground == 0)| TRUE | evaluated 4 times by 1 test | | FALSE | evaluated 13 times by 1 test |
| 4-13 |
| 166 | { | - |
| 167 | old_async_pid = last_asynchronous_pid; | - |
| 168 | last_asynchronous_pid = j->pgrp; | - |
| 169 | }executed 4 times by 1 test: end of block | 4 |
| 170 | | - |
| 171 | status = start_job (job, foreground); | - |
| 172 | | - |
| 173 | if (status >= 0)| TRUE | evaluated 17 times by 1 test | | FALSE | never evaluated |
| 0-17 |
| 174 | { | - |
| 175 | | - |
| 176 | UNBLOCK_CHILD (oset); | - |
| 177 | return (foreground ? status : EXECUTION_SUCCESS);executed 17 times by 1 test: return (foreground ? status : 0); | 17 |
| 178 | } | - |
| 179 | else | - |
| 180 | { | - |
| 181 | if (foreground == 0)| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 182 | last_asynchronous_pid = old_async_pid; never executed: last_asynchronous_pid = old_async_pid; | 0 |
| 183 | | - |
| 184 | failure: code before this statement never executed: failure: | 0 |
| 185 | UNBLOCK_CHILD (oset); | - |
| 186 | return (EXECUTION_FAILURE);executed 4 times by 1 test: return (1); | 4 |
| 187 | } | - |
| 188 | } | - |
| 189 | #endif /* JOB_CONTROL */ | - |
| | |