pulse-server: Use fprintf to write the pid file

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);
          |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:
Jan Alexander Steffens (heftig) 2021-03-13 20:09:31 +01:00
parent ac9bcdee31
commit c6aa48548e
No known key found for this signature in database
GPG key ID: 3B94A80E50A477C7

View file

@ -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;
}