Skip to content

Commit f117e31

Browse files
fix: exit the bsubmit with the same exit code as the bsub child process
Signed-off-by: Harikrishnan Balagopal <harikrishmenon@gmail.com>
1 parent 80e3207 commit f117e31

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

‎bsubmit/bsubmit.cpp‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ bool verifyUserMapping(std::string fpath, std::string execName)
279279
}
280280

281281

282-
void runcmd(std::string cmd)
282+
int runcmd(std::string cmd)
283283
{
284284
std::string readline;
285285
FILE * fp = popen(cmd.c_str(), "r");
@@ -290,7 +290,14 @@ void runcmd(std::string cmd)
290290
}
291291
}
292292

293-
pclose(fp);
293+
// pclose returns the termination status of the command
294+
int status = pclose(fp);
295+
296+
// Extract the exit code from the status
297+
// WEXITSTATUS is a macro that gets the actual return value (0-255)
298+
int exit_code = WEXITSTATUS(status);
299+
300+
return exit_code;
294301
}
295302

296303
int changeUser(char * execUser)
@@ -376,7 +383,7 @@ int main(int argc, char **argv)
376383
bsubcmd.append(" ");
377384
bsubcmd.append(argv[i]);
378385
}
379-
runcmd(bsubcmd);
386+
int exit_code = runcmd(bsubcmd);
380387

381-
return 0;
388+
return exit_code;
382389
}

0 commit comments

Comments
 (0)