Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 524388 | Differences between
and this patch

Collapse All | Expand All

(-)a/src/rc/start-stop-daemon.c (-14 / +27 lines)
Lines 673-678 start_stop_daemon(int argc, char **argv) Link Here
673
	char *startas = NULL;
673
	char *startas = NULL;
674
	char *name = NULL;
674
	char *name = NULL;
675
	char *pidfile = NULL;
675
	char *pidfile = NULL;
676
	char *spidfile; //chroot aware pidfile
676
	char *retry = NULL;
677
	char *retry = NULL;
677
	int sig = -1;
678
	int sig = -1;
678
	int nicelevel = 0, ionicec = -1, ioniced = 0;
679
	int nicelevel = 0, ionicec = -1, ioniced = 0;
Lines 1001-1010 start_stop_daemon(int argc, char **argv) Link Here
1001
		exit(EXIT_FAILURE);
1002
		exit(EXIT_FAILURE);
1002
	}
1003
	}
1003
1004
1005
	/* if we are chrooting our service then pidfile will be created
1006
	 * in the chroot folder, and it can't be controled in a natural way.
1007
	 * in order to workaround this problem we introducing a chroot aware
1008
	 * version of a pidfile variable.
1009
	 */
1010
	if (ch_root && pidfile) {
1011
	        spidfile = malloc(strlen(ch_root) + strlen(pidfile));
1012
		strcpy(spidfile, ch_root);
1013
		strcat(spidfile, pidfile);
1014
	} else {
1015
		spidfile = pidfile;
1016
	}
1017
1004
	/* If we don't have a pidfile we should check if it's interpreted
1018
	/* If we don't have a pidfile we should check if it's interpreted
1005
	 * or not. If it we, we need to pass the interpreter through
1019
	 * or not. If it we, we need to pass the interpreter through
1006
	 * to our daemon calls to find it correctly. */
1020
	 * to our daemon calls to find it correctly. */
1007
	if (interpreted && !pidfile) {
1021
	if (interpreted && !spidfile) {
1008
		fp = fopen(exec_file, "r");
1022
		fp = fopen(exec_file, "r");
1009
		if (fp) {
1023
		if (fp) {
1010
			p = fgets(line, sizeof(line), fp);
1024
			p = fgets(line, sizeof(line), fp);
Lines 1048-1054 start_stop_daemon(int argc, char **argv) Link Here
1048
		else
1062
		else
1049
			parse_schedule(NULL, sig);
1063
			parse_schedule(NULL, sig);
1050
		i = run_stop_schedule(exec, (const char *const *)margv,
1064
		i = run_stop_schedule(exec, (const char *const *)margv,
1051
		    pidfile, uid, test, progress);
1065
		    spidfile, uid, test, progress);
1052
1066
1053
		if (i < 0)
1067
		if (i < 0)
1054
			/* We failed to stop something */
1068
			/* We failed to stop something */
Lines 1060-1076 start_stop_daemon(int argc, char **argv) Link Here
1060
		 * remove information about it as it may have unexpectedly
1074
		 * remove information about it as it may have unexpectedly
1061
		 * crashed out. We should also return success as the end
1075
		 * crashed out. We should also return success as the end
1062
		 * result would be the same. */
1076
		 * result would be the same. */
1063
		if (pidfile && exists(pidfile))
1077
		if (spidfile && exists(spidfile))
1064
			unlink(pidfile);
1078
			unlink(spidfile);
1065
		if (svcname)
1079
		if (svcname)
1066
			rc_service_daemon_set(svcname, exec,
1080
			rc_service_daemon_set(svcname, exec,
1067
			    (const char *const *)argv,
1081
			    (const char *const *)argv,
1068
			    pidfile, false);
1082
			    spidfile, false);
1069
		exit(EXIT_SUCCESS);
1083
		exit(EXIT_SUCCESS);
1070
	}
1084
	}
1071
1085
1072
	if (pidfile)
1086
	if (spidfile)
1073
		pid = get_pid(pidfile);
1087
		pid = get_pid(spidfile);
1074
	else
1088
	else
1075
		pid = 0;
1089
		pid = 0;
1076
1090
Lines 1107-1114 start_stop_daemon(int argc, char **argv) Link Here
1107
	eindentv();
1121
	eindentv();
1108
1122
1109
	/* Remove existing pidfile */
1123
	/* Remove existing pidfile */
1110
	if (pidfile)
1124
	if (spidfile)
1111
		unlink(pidfile);
1125
		unlink(spidfile);
1112
1126
1113
	if (background)
1127
	if (background)
1114
		signal_setup(SIGCHLD, handle_signal);
1128
		signal_setup(SIGCHLD, handle_signal);
Lines 1341-1353 start_stop_daemon(int argc, char **argv) Link Here
1341
			if (kill(pid, 0) == 0)
1355
			if (kill(pid, 0) == 0)
1342
				alive = true;
1356
				alive = true;
1343
		} else {
1357
		} else {
1344
			if (pidfile) {
1358
			if (spidfile) {
1345
				pid = get_pid(pidfile);
1359
				pid = get_pid(spidfile);
1346
				if (pid == -1) {
1360
				if (pid == -1) {
1347
					eerrorx("%s: did not "
1361
					eerrorx("%s: did not "
1348
					    "create a valid"
1362
					    "create a valid"
1349
					    " pid in `%s'",
1363
					    " pid in `%s'",
1350
					    applet, pidfile);
1364
					    applet, spidfile);
1351
				}
1365
				}
1352
			} else
1366
			} else
1353
				pid = 0;
1367
				pid = 0;
Lines 1359-1368 start_stop_daemon(int argc, char **argv) Link Here
1359
		if (!alive)
1373
		if (!alive)
1360
			eerrorx("%s: %s died", applet, exec);
1374
			eerrorx("%s: %s died", applet, exec);
1361
	}
1375
	}
1362
1363
	if (svcname)
1376
	if (svcname)
1364
		rc_service_daemon_set(svcname, exec,
1377
		rc_service_daemon_set(svcname, exec,
1365
		    (const char *const *)margv, pidfile, true);
1378
		    (const char *const *)margv, spidfile, true);
1366
1379
1367
	exit(EXIT_SUCCESS);
1380
	exit(EXIT_SUCCESS);
1368
	/* NOTREACHED */
1381
	/* NOTREACHED */

Return to bug 524388