Browse Source

procd: Add %m to several functions that return errno.

Might help with debugging. No size impact.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Rosen Penev 6 years ago
parent
commit
a5954cf302
11 changed files with 33 additions and 37 deletions
  1. 1 1
      initd/early.c
  2. 2 2
      initd/init.c
  3. 6 6
      initd/preinit.c
  4. 4 4
      initd/zram.c
  5. 2 2
      inittab.c
  6. 1 1
      jail/fs.c
  7. 2 2
      plug/coldplug.c
  8. 7 7
      plug/hotplug.c
  9. 1 1
      rcS.c
  10. 4 8
      service/instance.c
  11. 3 3
      state.c

+ 1 - 1
initd/early.c

@@ -39,7 +39,7 @@ early_console(const char *dev)
 	struct stat s;
 
 	if (stat(dev, &s)) {
-		ERROR("Failed to stat %s\n", dev);
+		ERROR("Failed to stat %s: %m\n", dev);
 		return;
 	}
 

+ 2 - 2
initd/init.c

@@ -90,11 +90,11 @@ main(int argc, char **argv)
 			patch_stdio("/dev/null");
 
 		execvp(kmod[0], kmod);
-		ERROR("Failed to start kmodloader\n");
+		ERROR("Failed to start kmodloader: %m\n");
 		exit(-1);
 	}
 	if (pid <= 0) {
-		ERROR("Failed to start kmodloader instance\n");
+		ERROR("Failed to start kmodloader instance: %m\n");
 	} else {
 		int i;
 

+ 6 - 6
initd/preinit.c

@@ -42,7 +42,7 @@ check_dbglvl(void)
 	if (!fp)
 		return;
 	if (fscanf(fp, "%d", &lvl) == EOF)
-		ERROR("failed to read debug level\n");
+		ERROR("failed to read debug level: %m\n");
 	fclose(fp);
 	unlink("/tmp/debug_level");
 
@@ -134,11 +134,11 @@ preinit(void)
 	plugd_proc.pid = fork();
 	if (!plugd_proc.pid) {
 		execvp(plug[0], plug);
-		ERROR("Failed to start plugd\n");
+		ERROR("Failed to start plugd: %m\n");
 		exit(-1);
 	}
 	if (plugd_proc.pid <= 0) {
-		ERROR("Failed to start new plugd instance\n");
+		ERROR("Failed to start new plugd instance: %m\n");
 		return;
 	}
 	uloop_process_add(&plugd_proc);
@@ -148,7 +148,7 @@ preinit(void)
 	fd = creat("/tmp/.preinit", 0600);
 
 	if (fd < 0)
-		ERROR("Failed to create sentinel file\n");
+		ERROR("Failed to create sentinel file: %m\n");
 	else
 		close(fd);
 
@@ -156,11 +156,11 @@ preinit(void)
 	preinit_proc.pid = fork();
 	if (!preinit_proc.pid) {
 		execvp(init[0], init);
-		ERROR("Failed to start preinit\n");
+		ERROR("Failed to start preinit: %m\n");
 		exit(-1);
 	}
 	if (preinit_proc.pid <= 0) {
-		ERROR("Failed to start new preinit instance\n");
+		ERROR("Failed to start new preinit instance: %m\n");
 		return;
 	}
 	uloop_process_add(&preinit_proc);

+ 4 - 4
initd/zram.c

@@ -64,12 +64,12 @@ early_insmod(char *module)
 		sprintf(path, module, ver.release);
 		modprobe[1] = path;
 		execvp(modprobe[0], modprobe);
-		ERROR("Can't exec %s\n", modprobe[0]);
+		ERROR("Can't exec %s: %m\n", modprobe[0]);
 		exit(-1);
 	}
 
 	if (pid <= 0) {
-		ERROR("Can't exec %s\n", modprobe[0]);
+		ERROR("Can't exec %s: %m\n", modprobe[0]);
 		return -1;
 	} else {
 		waitpid(pid, NULL, 0);
@@ -107,10 +107,10 @@ mount_zram_on_tmp(void)
 	pid = fork();
 	if (!pid) {
 		execvp(mkfs[0], mkfs);
-		ERROR("Can't exec %s\n", mkfs[0]);
+		ERROR("Can't exec %s: %m\n", mkfs[0]);
 		exit(-1);
 	} else if (pid <= 0) {
-		ERROR("Can't exec %s\n", mkfs[0]);
+		ERROR("Can't exec %s: %m\n", mkfs[0]);
 		return -1;
 	} else {
 		waitpid(pid, NULL, 0);

+ 2 - 2
inittab.c

@@ -104,7 +104,7 @@ static void fork_worker(struct init_action *a)
 		tcsetpgrp(STDIN_FILENO, p);
 
 		execvp(a->argv[0], a->argv);
-		ERROR("Failed to execute %s\n", a->argv[0]);
+		ERROR("Failed to execute %s: %m\n", a->argv[0]);
 		exit(-1);
 	}
 
@@ -278,7 +278,7 @@ void procd_inittab(void)
 	char *line;
 
 	if (!fp) {
-		ERROR("Failed to open %s\n", tab);
+		ERROR("Failed to open %s: %m\n", tab);
 		return;
 	}
 

+ 1 - 1
jail/fs.c

@@ -153,7 +153,7 @@ int add_path_and_deps(const char *path, int readonly, int error, int lib)
 
 	map = mmap(NULL, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	if (map == MAP_FAILED) {
-		ERROR("failed to mmap %s\n", path);
+		ERROR("failed to mmap %s: %m\n", path);
 		ret = -1;
 		goto out;
 	}

+ 2 - 2
plug/coldplug.c

@@ -54,12 +54,12 @@ void procd_coldplug(void)
 	udevtrigger.pid = fork();
 	if (!udevtrigger.pid) {
 		execvp(argv[0], argv);
-		ERROR("Failed to start coldplug\n");
+		ERROR("Failed to start coldplug: %m\n");
 		exit(-1);
 	}
 
 	if (udevtrigger.pid <= 0) {
-		ERROR("Failed to start new coldplug instance\n");
+		ERROR("Failed to start new coldplug instance: %m\n");
 		return;
 	}
 

+ 7 - 7
plug/hotplug.c

@@ -238,7 +238,7 @@ static void handle_firmware(struct blob_attr *msg, struct blob_attr *data)
 	sprintf(path, "%s/%s", dir, file);
 
 	if (stat(path, &s)) {
-		ERROR("Could not find firmware %s\n", path);
+		ERROR("Could not find firmware %s: %m\n", path);
 		src = -1;
 		s.st_size = 0;
 		goto send_to_kernel;
@@ -246,7 +246,7 @@ static void handle_firmware(struct blob_attr *msg, struct blob_attr *data)
 
 	src = open(path, O_RDONLY);
 	if (src < 0) {
-		ERROR("Failed to open %s\n", path);
+		ERROR("Failed to open %s: %m\n", path);
 		s.st_size = 0;
 		goto send_to_kernel;
 	}
@@ -255,11 +255,11 @@ send_to_kernel:
 	snprintf(loadpath, sizeof(loadpath), "/sys/%s/loading", dev);
 	load = open(loadpath, O_WRONLY);
 	if (!load) {
-		ERROR("Failed to open %s\n", loadpath);
+		ERROR("Failed to open %s: %m\n", loadpath);
 		exit(-1);
 	}
 	if (write(load, "1", 1) == -1) {
-		ERROR("Failed to write to %s\n", loadpath);
+		ERROR("Failed to write to %s: %m\n", loadpath);
 		exit(-1);
 	}
 	close(load);
@@ -267,7 +267,7 @@ send_to_kernel:
 	snprintf(syspath, sizeof(syspath), "/sys/%s/data", dev);
 	fw = open(syspath, O_WRONLY);
 	if (fw < 0) {
-		ERROR("Failed to open %s\n", syspath);
+		ERROR("Failed to open %s: %m\n", syspath);
 		exit(-1);
 	}
 
@@ -278,7 +278,7 @@ send_to_kernel:
 			break;
 
 		if (write(fw, buf, len) == -1) {
-			ERROR("failed to write firmware file %s/%s to %s\n", dir, file, dev);
+			ERROR("failed to write firmware file %s/%s to %s: %m\n", dir, file, dev);
 			break;
 		}
 	}
@@ -289,7 +289,7 @@ send_to_kernel:
 
 	load = open(loadpath, O_WRONLY);
 	if (write(load, "0", 1) == -1)
-		ERROR("failed to write to %s\n", loadpath);
+		ERROR("failed to write to %s: %m\n", loadpath);
 	close(load);
 
 	DEBUG(2, "Done loading %s\n", path);

+ 1 - 1
rcS.c

@@ -72,7 +72,7 @@ static void q_initd_run(struct runqueue *q, struct runqueue_task *t)
 
 	DEBUG(2, "start %s %s \n", s->file, s->param);
 	if (pipe(pipefd) == -1) {
-		ERROR("Failed to create pipe\n");
+		ERROR("Failed to create pipe: %m\n");
 		return;
 	}
 

+ 4 - 8
service/instance.c

@@ -241,8 +241,7 @@ instance_removepid(struct service_instance *in) {
 	if (!in->pidfile)
 		return 0;
 	if (unlink(in->pidfile)) {
-		ERROR("Failed to removed pidfile: %s: %m\n",
-			in->pidfile);
+		ERROR("Failed to removed pidfile: %s: %m\n", in->pidfile);
 		return 1;
 	}
 	return 0;
@@ -258,19 +257,16 @@ instance_writepid(struct service_instance *in)
 	}
 	_pidfile = fopen(in->pidfile, "w");
 	if (_pidfile == NULL) {
-		ERROR("failed to open pidfile for writing: %s: %m",
-			in->pidfile);
+		ERROR("failed to open pidfile for writing: %s: %m", in->pidfile);
 		return 1;
 	}
 	if (fprintf(_pidfile, "%d\n", in->proc.pid) < 0) {
-		ERROR("failed to write pidfile: %s: %m",
-			in->pidfile);
+		ERROR("failed to write pidfile: %s: %m", in->pidfile);
 		fclose(_pidfile);
 		return 2;
 	}
 	if (fclose(_pidfile)) {
-		ERROR("failed to close pidfile: %s: %m",
-			in->pidfile);
+		ERROR("failed to close pidfile: %s: %m", in->pidfile);
 		return 3;
 	}
 

+ 3 - 3
state.c

@@ -48,7 +48,7 @@ static void set_stdio(const char* tty)
 	    !freopen(tty, "w", stdout) ||
 	    !freopen(tty, "w", stderr) ||
 	    chdir("/"))
-		ERROR("failed to set stdio\n");
+		ERROR("failed to set stdio: %m\n");
 	else
 		fcntl(STDERR_FILENO, F_SETFL, fcntl(STDERR_FILENO, F_GETFL) | O_NONBLOCK);
 }
@@ -73,7 +73,7 @@ static void set_console(void)
 	}
 
 	if (chdir("/dev")) {
-		ERROR("failed to change dir to /dev\n");
+		ERROR("failed to change dir to /dev: %m\n");
 		return;
 	}
 	while (tty!=NULL) {
@@ -87,7 +87,7 @@ static void set_console(void)
 		i++;
 	}
 	if (chdir("/"))
-		ERROR("failed to change dir to /\n");
+		ERROR("failed to change dir to /: %m\n");
 
 	if (tty != NULL)
 		set_stdio(tty);