Skip to content

Commit b33b962

Browse files
committed
feat sdbd: added shell interpreter exist check
Signed-off-by: John Sanpe <[email protected]>
1 parent 9bf2bd2 commit b33b962

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

sdbd.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,7 +3476,7 @@ spawn_daemon(void)
34763476
pid = fork();
34773477
switch (pid) {
34783478
case -1:
3479-
fprintf(stderr, "failed to fork daemon\n");
3479+
fprintf(stderr, "Failed to fork daemon\n");
34803480
return -BFDEV_EFAULT;
34813481

34823482
case 0:
@@ -3488,27 +3488,27 @@ spawn_daemon(void)
34883488

34893489
fd = open("/dev/null", O_RDWR);
34903490
if (fd < 0) {
3491-
fprintf(stderr, "failed to open null\n");
3491+
fprintf(stderr, "Failed to open null\n");
34923492
return -BFDEV_ENXIO;
34933493
}
34943494

34953495
if (isatty(STDIN_FILENO)) {
34963496
if (dup2(fd, STDIN_FILENO) < 0) {
3497-
fprintf(stderr, "failed to dup stdin\n");
3497+
fprintf(stderr, "Failed to dup stdin\n");
34983498
return -BFDEV_ENXIO;
34993499
}
35003500
}
35013501

35023502
if (isatty(STDOUT_FILENO)) {
35033503
if (dup2(fd, STDOUT_FILENO) < 0) {
3504-
fprintf(stderr, "failed to dup stdout\n");
3504+
fprintf(stderr, "Failed to dup stdout\n");
35053505
return -BFDEV_ENXIO;
35063506
}
35073507
}
35083508

35093509
if (isatty(STDERR_FILENO)) {
35103510
if (dup2(fd, STDERR_FILENO) < 0) {
3511-
fprintf(stderr, "failed to dup stdout\n");
3511+
fprintf(stderr, "Failed to dup stdout\n");
35123512
return -BFDEV_ENXIO;
35133513
}
35143514
}
@@ -3591,6 +3591,7 @@ main(int argc, char *const argv[])
35913591
{
35923592
unsigned long value;
35933593
int arg, optidx, logfd;
3594+
struct stat stbuf;
35943595
int retval;
35953596

35963597
logfd = -1;
@@ -3679,6 +3680,11 @@ main(int argc, char *const argv[])
36793680
if (!sdbd_shell)
36803681
sdbd_shell = "/bin/sh";
36813682

3683+
if (stat(sdbd_shell, &stbuf)) {
3684+
fprintf(stderr, "Shell interpreter not found: '%s'\n", sdbd_shell);
3685+
exit(1);
3686+
}
3687+
36823688
if (sdbd_daemon) {
36833689
retval = spawn_daemon();
36843690
if (retval < 0)

0 commit comments

Comments
 (0)