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/librc/librc-daemon.c (-4 / +16 lines)
Lines 553-568 rc_service_daemons_crashed(const char *service) Link Here
553
		}
553
		}
554
		fclose(fp);
554
		fclose(fp);
555
555
556
		char *ch_root = rc_service_value_get(basename_c(service), "chroot");
557
		char *spidfile = pidfile;
558
		if (ch_root) {
559
			spidfile = malloc(strlen(ch_root) + strlen(pidfile));
560
			strcpy(spidfile, ch_root);
561
			strcat(spidfile, pidfile);
562
		}
563
556
		pid = 0;
564
		pid = 0;
557
		if (pidfile) {
565
		if (spidfile) {
558
			retval = true;
566
			retval = true;
559
			if ((fp = fopen(pidfile, "r"))) {
567
			if ((fp = fopen(spidfile, "r"))) {
560
				if (fscanf(fp, "%d", &pid) == 1)
568
				if (fscanf(fp, "%d", &pid) == 1)
561
					retval = false;
569
					retval = false;
562
				fclose(fp);
570
				fclose(fp);
563
			}
571
			}
564
			free(pidfile);
572
			free(spidfile);
565
			pidfile = NULL;
573
			spidfile = NULL;
574
			if (ch_root) {
575
				free(pidfile);
576
				pidfile = NULL;
577
			}
566
578
567
			/* We have the pid, so no need to match
579
			/* We have the pid, so no need to match
568
			   on exec or name */
580
			   on exec or name */
(-)a/src/rc/start-stop-daemon.c (-13 / +33 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 = NULL; //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 (stop && !ch_root) {
1006
		ch_root = rc_service_value_get(svcname, "chroot");
1007
	}
1008
1009
	/* if we are chrooting our service then pidfile will be created
1010
	 * in the chroot folder, and it can't be controled in a natural way.
1011
	 * in order to workaround this problem we introducing a chroot aware
1012
	 * version of a pidfile variable.
1013
	 */
1014
	if (ch_root && pidfile) {
1015
	        spidfile = malloc(strlen(ch_root) + strlen(pidfile));
1016
		strcpy(spidfile, ch_root);
1017
		strcat(spidfile, pidfile);
1018
	} else {
1019
		spidfile = pidfile;
1020
	}
1021
1004
	/* If we don't have a pidfile we should check if it's interpreted
1022
	/* 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
1023
	 * or not. If it we, we need to pass the interpreter through
1006
	 * to our daemon calls to find it correctly. */
1024
	 * to our daemon calls to find it correctly. */
1007
	if (interpreted && !pidfile) {
1025
	if (interpreted && !spidfile) {
1008
		fp = fopen(exec_file, "r");
1026
		fp = fopen(exec_file, "r");
1009
		if (fp) {
1027
		if (fp) {
1010
			p = fgets(line, sizeof(line), fp);
1028
			p = fgets(line, sizeof(line), fp);
Lines 1048-1054 start_stop_daemon(int argc, char **argv) Link Here
1048
		else
1066
		else
1049
			parse_schedule(NULL, sig);
1067
			parse_schedule(NULL, sig);
1050
		i = run_stop_schedule(exec, (const char *const *)margv,
1068
		i = run_stop_schedule(exec, (const char *const *)margv,
1051
		    pidfile, uid, test, progress);
1069
		    spidfile, uid, test, progress);
1052
1070
1053
		if (i < 0)
1071
		if (i < 0)
1054
			/* We failed to stop something */
1072
			/* We failed to stop something */
Lines 1060-1067 start_stop_daemon(int argc, char **argv) Link Here
1060
		 * remove information about it as it may have unexpectedly
1078
		 * remove information about it as it may have unexpectedly
1061
		 * crashed out. We should also return success as the end
1079
		 * crashed out. We should also return success as the end
1062
		 * result would be the same. */
1080
		 * result would be the same. */
1063
		if (pidfile && exists(pidfile))
1081
		if (spidfile && exists(spidfile))
1064
			unlink(pidfile);
1082
			unlink(spidfile);
1065
		if (svcname)
1083
		if (svcname)
1066
			rc_service_daemon_set(svcname, exec,
1084
			rc_service_daemon_set(svcname, exec,
1067
			    (const char *const *)argv,
1085
			    (const char *const *)argv,
Lines 1069-1076 start_stop_daemon(int argc, char **argv) Link Here
1069
		exit(EXIT_SUCCESS);
1087
		exit(EXIT_SUCCESS);
1070
	}
1088
	}
1071
1089
1072
	if (pidfile)
1090
	if (spidfile)
1073
		pid = get_pid(pidfile);
1091
		pid = get_pid(spidfile);
1074
	else
1092
	else
1075
		pid = 0;
1093
		pid = 0;
1076
1094
Lines 1107-1114 start_stop_daemon(int argc, char **argv) Link Here
1107
	eindentv();
1125
	eindentv();
1108
1126
1109
	/* Remove existing pidfile */
1127
	/* Remove existing pidfile */
1110
	if (pidfile)
1128
	if (spidfile)
1111
		unlink(pidfile);
1129
		unlink(spidfile);
1112
1130
1113
	if (background)
1131
	if (background)
1114
		signal_setup(SIGCHLD, handle_signal);
1132
		signal_setup(SIGCHLD, handle_signal);
Lines 1341-1353 start_stop_daemon(int argc, char **argv) Link Here
1341
			if (kill(pid, 0) == 0)
1359
			if (kill(pid, 0) == 0)
1342
				alive = true;
1360
				alive = true;
1343
		} else {
1361
		} else {
1344
			if (pidfile) {
1362
			if (spidfile) {
1345
				pid = get_pid(pidfile);
1363
				pid = get_pid(spidfile);
1346
				if (pid == -1) {
1364
				if (pid == -1) {
1347
					eerrorx("%s: did not "
1365
					eerrorx("%s: did not "
1348
					    "create a valid"
1366
					    "create a valid"
1349
					    " pid in `%s'",
1367
					    " pid in `%s'",
1350
					    applet, pidfile);
1368
					    applet, spidfile);
1351
				}
1369
				}
1352
			} else
1370
			} else
1353
				pid = 0;
1371
				pid = 0;
Lines 1359-1368 start_stop_daemon(int argc, char **argv) Link Here
1359
		if (!alive)
1377
		if (!alive)
1360
			eerrorx("%s: %s died", applet, exec);
1378
			eerrorx("%s: %s died", applet, exec);
1361
	}
1379
	}
1362
1380
	if (svcname) {
1363
	if (svcname)
1364
		rc_service_daemon_set(svcname, exec,
1381
		rc_service_daemon_set(svcname, exec,
1365
		    (const char *const *)margv, pidfile, true);
1382
		    (const char *const *)margv, pidfile, true);
1383
		if (ch_root)
1384
			rc_service_value_set(svcname, "chroot", ch_root);
1385
	}
1366
1386
1367
	exit(EXIT_SUCCESS);
1387
	exit(EXIT_SUCCESS);
1368
	/* NOTREACHED */
1388
	/* NOTREACHED */

Return to bug 524388