From c6aa48548e5d1ed430ddeeef85c2a09c10539a8e Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Sat, 13 Mar 2021 20:09:31 +0100 Subject: [PATCH] pulse-server: Use fprintf to write the pid file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This simplifies the code and also avoids a warning with _FORTIFY_SOURCE: ../pipewire/src/modules/module-protocol-pulse/pulse-server.c: In function ‘create_pid_file’: ../pipewire/src/modules/module-protocol-pulse/pulse-server.c:6028:2: warning: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 6028 | write(fd, pid_str, strlen(pid_str) + 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- src/modules/module-protocol-pulse/pulse-server.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index d9989a541..9539f1155 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -6010,7 +6010,7 @@ error: static int create_pid_file(void) { int res; char pid_file[PATH_MAX]; - char pid_str[32]; + FILE *f; if ((res = get_runtime_dir(pid_file, sizeof(pid_file), "pulse")) < 0) { return res; @@ -6021,16 +6021,14 @@ static int create_pid_file(void) { } strcat(pid_file, "/pid"); - snprintf(pid_str, sizeof(pid_str), "%lu\n", (unsigned long)getpid()); - - int fd = open(pid_file, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); - if (fd < 0) { + if ((f = fopen(pid_file, "w")) == NULL) { res = -errno; pw_log_error(NAME" failed to open pid file"); return res; } - write(fd, pid_str, strlen(pid_str) + 1); - close(fd); + + fprintf(f, "%lu\n", (unsigned long)getpid()); + fclose(f); return 0; }