[pulseaudio-discuss] [PATCH 1/2] Log feature:Add a new log target to a file descriptor

Becker, VincentX vincentx.becker at intel.com
Wed Mar 9 09:15:39 PST 2011


>-----Original Message-----
>From: pulseaudio-discuss-bounces at mail.0pointer.de [mailto:pulseaudio-
>discuss-bounces at mail.0pointer.de] On Behalf Of Maarten Bosmans
>Sent: Wednesday, March 09, 2011 5:31 PM
>To: General PulseAudio Discussion
>Subject: Re: [pulseaudio-discuss] [PATCH 1/2] Log feature:Add a new log
>target to a file descriptor
>
>2011/3/9 Vincent Becker <vincentx.becker at intel.com>:
>> @@ -185,7 +193,23 @@ int pa_daemon_conf_set_log_target(pa_daemon_conf
>*c, const char *string) {
>>     } else if (!strcmp(string, "stderr")) {
>>         c->auto_log_target = 0;
>>         c->log_target = PA_LOG_STDERR;
>> -    } else
>> +    } else if (pa_startswith(string, "file:")) {
>> +        char file_path[512];
>> +
>> +        strncpy(file_path, string+5, sizeof(file_path));
>
>This is potentially unsafe, use pa_strlcpy.

Ok I will use it instead.

>
>> +
>> +        /* Open target file with user rights */
>> +        if ((log_fd = open(file_path, O_RDWR|O_TRUNC|O_CREAT,
>S_IRWXU)) >= 0) {
>> +            c->auto_log_target = 0;
>> +            c->log_target = PA_LOG_FD;
>> +            pa_log_set_fd(log_fd);
>> +        }
>> +        else {
>> +            printf("Failed to open target file %s, error : %s\n",
>file_path, pa_cstrerror(errno));
>> +            return -1;
>> +        }
>> +    }
>> +    else
>>         return -1;
>>
>>     return 0;
>
>
>> @@ -399,6 +407,24 @@ void pa_log_levelv_meta(
>>             }
>>  #endif
>>
>> +            case PA_LOG_FD: {
>> +                if (log_fd != -1) {
>> +                    char metadata[256];
>> +
>> +                    pa_snprintf(metadata, sizeof(metadata), "\n%c
>%s%s", level_to_char[level], timestamp, location);
>> +
>> +                    if ((write(log_fd, metadata, strlen(metadata)) <
>0) || (write(log_fd, t, strlen(t)) < 0)) {
>> +                        saved_errno = errno;
>> +                        pa_close(log_fd);
>> +                        log_fd = -1;
>> +                    }
>> +                }
>> +                else
>> +                    fprintf(stderr, "%s\n", "Invalid file descriptor.
>Could not write log message.");
>
>Wouldn't this result in lots and lots of the same messages to stderr?
>It seems better to move this message to the case when the write fails,
>or just print the log message here, or both.

Yes it will indeed. So we probably prefer to print first the log message itself then print a warning message with the errno - using printf, then change the target dynamically to PA_LOG_STDERR as Arun suggested, using pa_log_set_target(). Also the target in daemon configuration will stay PA_LOG_FD which should be no problem. Also calling twice pa_close is harmless I guess, but we could probably remove it from here. 

>
>> +
>> +                break;
>> +            }
>> +
>>             case PA_LOG_NULL:
>>             default:
>>                 break;
>
>Maarten
>_______________________________________________
>pulseaudio-discuss mailing list
>pulseaudio-discuss at mail.0pointer.de
>https://tango.0pointer.de/mailman/listinfo/pulseaudio-discuss
---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


More information about the pulseaudio-discuss mailing list