From 882614ab0796ba8a757d188d13564b4eed477322 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Tue, 15 Apr 2025 14:28:10 +0100 Subject: [PATCH] cast pid_t to int when used in format strings Silences warnings on Solaris --- compat/pidfile.c | 2 +- src/dhcp.c | 2 +- src/dhcpcd.c | 12 ++++++------ src/ipv4ll.c | 2 +- src/ipv6.c | 2 +- src/logerr.c | 2 +- src/route.c | 2 +- src/script.c | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/compat/pidfile.c b/compat/pidfile.c index 8d2e5a83..b89738bd 100644 --- a/compat/pidfile.c +++ b/compat/pidfile.c @@ -257,7 +257,7 @@ return_pid: * Then write the process ID. */ if (ftruncate(pidfile_fd, 0) == -1 || lseek(pidfile_fd, 0, SEEK_SET) == -1 || - dprintf(pidfile_fd, "%d\n", pidfile_pid) == -1) + dprintf(pidfile_fd, "%d\n", (int)pidfile_pid) == -1) { int error = errno; diff --git a/src/dhcp.c b/src/dhcp.c index 436399cb..b294bd67 100644 --- a/src/dhcp.c +++ b/src/dhcp.c @@ -4335,7 +4335,7 @@ dhcp_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) if (cmd == RTM_DELADDR) { if (state->addr == ia) { loginfox("%s: pid %d deleted IP address %s", - ifp->name, pid, ia->saddr); + ifp->name, (int)pid, ia->saddr); dhcp_close(ifp); state->addr = NULL; /* Don't clear the added state as we need diff --git a/src/dhcpcd.c b/src/dhcpcd.c index 7cea7bd5..3e138cbc 100644 --- a/src/dhcpcd.c +++ b/src/dhcpcd.c @@ -1896,7 +1896,7 @@ dhcpcd_pidfile_timeout(void *arg) if(pid == -1) eloop_exit(ctx->eloop, EXIT_SUCCESS); else if (++ctx->duid_len >= 100) { /* overload duid_len */ - logerrx("pid %d failed to exit", pid); + logerrx("pid %d failed to exit", (int)pid); eloop_exit(ctx->eloop, EXIT_FAILURE); } else eloop_timeout_add_msec(ctx->eloop, 100, @@ -2247,7 +2247,7 @@ printpidfile: if (sig != 0) { pid = pidfile_read(ctx.pidfile); if (pid != 0 && pid != -1) - loginfox("sending signal %s to pid %d", siga, pid); + loginfox("sending signal %s to pid %d", siga, (int)pid); if (pid == 0 || pid == -1 || kill(pid, sig) != 0) { if (pid != 0 && pid != -1 && errno != ESRCH) { logerr("kill"); @@ -2260,7 +2260,7 @@ printpidfile: if (sig == SIGHUP || sig == SIGUSR1) goto exit_success; /* Spin until it exits */ - loginfox("waiting for pid %d to exit", pid); + loginfox("waiting for pid %d to exit", (int)pid); dhcpcd_pidfile_timeout(&ctx); goto run_loop; } @@ -2386,7 +2386,7 @@ printpidfile: else logerrx(PACKAGE " already running on pid %d (%s)", - pid, ctx.pidfile); + (int)pid, ctx.pidfile); goto exit_failure; } } @@ -2467,12 +2467,12 @@ printpidfile: /* We have now forked, setsid, forked once more. * From this point on, we are the controlling daemon. */ - logdebugx("spawned manager process on PID %d", getpid()); + logdebugx("spawned manager process on PID %d", (int)getpid()); start_manager: ctx.options |= DHCPCD_STARTED; if ((pid = pidfile_lock(ctx.pidfile)) != 0) { - logerr("%s: pidfile_lock %d", __func__, pid); + logerr("%s: pidfile_lock %d", __func__, (int)pid); #ifdef PRIVSEP /* privsep has not started ... */ ctx.options &= ~DHCPCD_PRIVSEP; diff --git a/src/ipv4ll.c b/src/ipv4ll.c index 94e6f4d9..c2c7a8e7 100644 --- a/src/ipv4ll.c +++ b/src/ipv4ll.c @@ -548,7 +548,7 @@ ipv4ll_handleifa(int cmd, struct ipv4_addr *ia, pid_t pid) IN_ARE_ADDR_EQUAL(&state->addr->addr, &ia->addr)) { loginfox("%s: pid %d deleted IP address %s", - ifp->name, pid, ia->saddr); + ifp->name, (int)pid, ia->saddr); ipv4ll_defend_failed(ifp); return ia; } diff --git a/src/ipv6.c b/src/ipv6.c index 32b349bb..107e5988 100644 --- a/src/ipv6.c +++ b/src/ipv6.c @@ -1849,7 +1849,7 @@ ipv6_handleifa_addrs(int cmd, if (cmd == RTM_DELADDR && ia->flags & IPV6_AF_ADDED) logwarnx("%s: pid %d deleted address %s", - ia->iface->name, pid, ia->saddr); + ia->iface->name, (int)pid, ia->saddr); /* Check DAD. * On Linux we can get IN6_IFF_DUPLICATED via RTM_DELADDR. */ diff --git a/src/logerr.c b/src/logerr.c index a0c5d35f..98cd1c7e 100644 --- a/src/logerr.c +++ b/src/logerr.c @@ -163,7 +163,7 @@ vlogprintf_r(struct logctx *ctx, FILE *stream, const char *fmt, va_list args) pid = getpid(); else pid = ctx->log_pid; - if ((e = fprintf(stream, "[%d]", pid)) == -1) + if ((e = fprintf(stream, "[%d]", (int)pid)) == -1) return -1; len += e; } diff --git a/src/route.c b/src/route.c index 0037dda4..cf3a7056 100644 --- a/src/route.c +++ b/src/route.c @@ -490,7 +490,7 @@ rt_recvrt(int cmd, const struct rt *rt, pid_t pid) char buf[32]; rb_tree_remove_node(&ctx->routes, f); - snprintf(buf, sizeof(buf), "pid %d deleted", pid); + snprintf(buf, sizeof(buf), "pid %d deleted", (int)pid); rt_desc(LOG_WARNING, buf, f); rt_free(f); } diff --git a/src/script.c b/src/script.c index abf62f60..0149aee9 100644 --- a/src/script.c +++ b/src/script.c @@ -279,7 +279,7 @@ make_env(struct dhcpcd_ctx *ctx, const struct interface *ifp, if (efprintf(fp, "PATH=%s", path == NULL ? DEFAULT_PATH : path) == -1) goto eexit; - if (efprintf(fp, "pid=%d", getpid()) == -1) + if (efprintf(fp, "pid=%d", (int)getpid()) == -1) goto eexit; } -- 2.47.2