Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 138409
Collapse All | Expand All

(-)baselayout-1.12.6/src/start-stop-daemon.orig.c (-3 / +52 lines)
Lines 27-32 Link Here
27
 * new root if -r option is used!).
27
 * new root if -r option is used!).
28
 * Daemon binary will be stat()ed correctly if it's going to be chrooted
28
 * Daemon binary will be stat()ed correctly if it's going to be chrooted
29
 * with -r|--chroot.
29
 * with -r|--chroot.
30
 *
31
 * Changes by Iain Buchanan <iaindb@netspace.net.au>: added to public domain.
32
 * Added --stdin --stdout and --stderr for redirecting input and output (eg to
33
 * vt's) when run with --background.
30
 * 
34
 * 
31
 */
35
 */
32
36
Lines 137-142 Link Here
137
static const char *schedule_str = NULL;
141
static const char *schedule_str = NULL;
138
static const char *progname = "";
142
static const char *progname = "";
139
static int nicelevel = 0;
143
static int nicelevel = 0;
144
static const char *stdindev  = NULL;
145
static const char *stdoutdev = NULL;
146
static const char *stderrdev = NULL;
140
147
141
static struct stat exec_stat;
148
static struct stat exec_stat;
142
#if defined(OSHURD)
149
#if defined(OSHURD)
Lines 308-313 Link Here
308
"  -o|--oknodo                   exit status 0 (not 1) if nothing done\n"
315
"  -o|--oknodo                   exit status 0 (not 1) if nothing done\n"
309
"  -q|--quiet                    be more quiet\n"
316
"  -q|--quiet                    be more quiet\n"
310
"  -v|--verbose                  be more verbose\n"
317
"  -v|--verbose                  be more verbose\n"
318
"  -0|--stdin <device>           redirect stdin from <device> when run with --background\n"
319
"  -1|--stdout <device>          redirect stdout to <device> when run with --background\n"
320
"  -2|--stderr <device>          redirect stderr to <device> when run with --background\n"
311
"Retry <schedule> is <item>|/<item>/... where <item> is one of\n"
321
"Retry <schedule> is <item>|/<item>/... where <item> is one of\n"
312
" -<signal-num>|[-]<signal-name>  send that signal\n"
322
" -<signal-num>|[-]<signal-name>  send that signal\n"
313
" <timeout>                       wait that many seconds\n"
323
" <timeout>                       wait that many seconds\n"
Lines 490-495 Link Here
490
		{ "make-pidfile", 0, NULL, 'm'},
500
		{ "make-pidfile", 0, NULL, 'm'},
491
		{ "retry",        1, NULL, 'R'},
501
		{ "retry",        1, NULL, 'R'},
492
		{ "chdir",        1, NULL, 'd'},
502
		{ "chdir",        1, NULL, 'd'},
503
		{ "stdin",        1, NULL, '0'},
504
		{ "stdout",       1, NULL, '1'},
505
		{ "stderr",       1, NULL, '2'},
493
		{ NULL,           0, NULL, 0}
506
		{ NULL,           0, NULL, 0}
494
	};
507
	};
495
	int c;
508
	int c;
Lines 573-578 Link Here
573
		case 'd':  /* --chdir /new/dir */
586
		case 'd':  /* --chdir /new/dir */
574
			changedir = optarg;
587
			changedir = optarg;
575
			break;
588
			break;
589
      case '0': /* --stdin new_stdin */
590
         stdindev = optarg;
591
         break;
592
      case '1': /* --stdout new_stdout */
593
         stdoutdev = optarg;
594
         break;
595
      case '2': /* --stderr new_stderr */
596
         stderrdev = optarg;
597
         break;
598
         
576
		default:
599
		default:
577
			badusage(NULL);  /* message printed by getopt */
600
			badusage(NULL);  /* message printed by getopt */
578
		}
601
		}
Lines 606-611 Link Here
606
	if (background && !start)
629
	if (background && !start)
607
		badusage("--background is only relevant with --start");
630
		badusage("--background is only relevant with --start");
608
631
632
   if ((stdindev != NULL || stdoutdev != NULL || stderrdev != NULL) && !background) {
633
      fprintf(stderr, "start-stop-daemon: redirecting stdin, stdout or stderr without --background\n");
634
      fprintf(stderr, "may stop you from interacting with this process from the terminal.\n");
635
   }
609
}
636
}
610
637
611
#if defined(OSLinux)
638
#if defined(OSLinux)
Lines 1255-1260 Link Here
1255
main(int argc, char **argv)
1282
main(int argc, char **argv)
1256
{
1283
{
1257
	int devnull_fd = -1;
1284
	int devnull_fd = -1;
1285
   int stdin_fd  = -1;
1286
   int stdout_fd = -1;
1287
   int stderr_fd = -1;
1258
#ifdef HAVE_TIOCNOTTY
1288
#ifdef HAVE_TIOCNOTTY
1259
	int tty_fd = -1;
1289
	int tty_fd = -1;
1260
#endif
1290
#endif
Lines 1364-1369 Link Here
1364
#endif
1394
#endif
1365
		devnull_fd=open("/dev/null", O_RDWR);
1395
		devnull_fd=open("/dev/null", O_RDWR);
1366
	}
1396
	}
1397
   if (stdindev != NULL)
1398
      stdin_fd=open(stdindev, O_RDWR | O_APPEND);
1399
   if (stdoutdev != NULL)
1400
      stdout_fd=open(stdoutdev, O_RDWR | O_APPEND);
1401
   if (stderrdev != NULL)
1402
      stderr_fd=open(stderrdev, O_RDWR | O_APPEND);
1367
	if (nicelevel) {
1403
	if (nicelevel) {
1368
		errno=0;
1404
		errno=0;
1369
		if ((nice(nicelevel)==-1) && (errno!=0))
1405
		if ((nice(nicelevel)==-1) && (errno!=0))
Lines 1407-1415 Link Here
1407
		close(tty_fd);
1443
		close(tty_fd);
1408
#endif
1444
#endif
1409
		umask(022); /* set a default for dumb programs */
1445
		umask(022); /* set a default for dumb programs */
1410
		dup2(devnull_fd,0); /* stdin */
1446
1411
		dup2(devnull_fd,1); /* stdout */
1412
		dup2(devnull_fd,2); /* stderr */
1413
#if defined(OShpux)
1447
#if defined(OShpux)
1414
		 /* now close all extra fds */
1448
		 /* now close all extra fds */
1415
		for (i=sysconf(_SC_OPEN_MAX)-1; i>=3; --i) close(i);
1449
		for (i=sysconf(_SC_OPEN_MAX)-1; i>=3; --i) close(i);
Lines 1425-1430 Link Here
1425
		setpgid(0,0);
1459
		setpgid(0,0);
1426
#endif
1460
#endif
1427
	}
1461
	}
1462
   if (stdin_fd == -1)
1463
      dup2(devnull_fd,0); /* stdin */
1464
   else
1465
      dup2(stdin_fd,0);   /* stdin */
1466
   
1467
   if (stdout_fd == -1)
1468
      dup2(devnull_fd,1); /* stdout */
1469
   else
1470
      dup2(stdout_fd,1);  /* stdout */
1471
   
1472
   if (stderr_fd == -1)
1473
      dup2(devnull_fd,2); /* stderr */
1474
   else
1475
      dup2(stderr_fd,2);  /* stderr */
1476
1428
	execv(startas, argv);
1477
	execv(startas, argv);
1429
	fatal("Unable to start %s: %s", startas, strerror(errno));
1478
	fatal("Unable to start %s: %s", startas, strerror(errno));
1430
}
1479
}

Return to bug 138409