@@ -116,14 +116,10 @@ static int compare_pstore_entries(const void *_a, const void *_b) {
116116}
117117
118118static int move_file (PStoreEntry * pe , const char * subdir ) {
119- _cleanup_free_ char * ifd_path = NULL ;
120- _cleanup_free_ char * ofd_path = NULL ;
121- int r = 0 ;
122- struct iovec iovec [2 ] = {};
123- int n_iovec = 0 ;
124- _cleanup_free_ void * field = NULL ;
125- const char * suffix = NULL ;
126- size_t field_size ;
119+ _cleanup_free_ char * ifd_path = NULL , * ofd_path = NULL ;
120+ const char * suffix , * message ;
121+ struct iovec iovec [2 ];
122+ int n_iovec = 0 , r ;
127123
128124 if (pe -> handled )
129125 return 0 ;
@@ -138,15 +134,20 @@ static int move_file(PStoreEntry *pe, const char *subdir) {
138134
139135 /* Always log to the journal */
140136 suffix = arg_storage == PSTORE_STORAGE_EXTERNAL ? strjoina (" moved to " , ofd_path ) : (char * )"." ;
141- field = strjoina ("MESSAGE=PStore " , pe -> dirent .d_name , suffix );
142- iovec [n_iovec ++ ] = IOVEC_MAKE_STRING (field );
137+ message = strjoina ("MESSAGE=PStore " , pe -> dirent .d_name , suffix );
138+ iovec [n_iovec ++ ] = IOVEC_MAKE_STRING (message );
143139
144- field_size = strlen ("FILE=" ) + pe -> content_size ;
145- field = malloc (field_size );
146- if (!field )
147- return log_oom ();
148- memcpy (stpcpy (field , "FILE=" ), pe -> content , pe -> content_size );
149- iovec [n_iovec ++ ] = IOVEC_MAKE (field , field_size );
140+ if (pe -> content_size > 0 ) {
141+ _cleanup_free_ void * field = NULL ;
142+ size_t field_size ;
143+
144+ field_size = strlen ("FILE=" ) + pe -> content_size ;
145+ field = malloc (field_size );
146+ if (!field )
147+ return log_oom ();
148+ memcpy (stpcpy (field , "FILE=" ), pe -> content , pe -> content_size );
149+ iovec [n_iovec ++ ] = IOVEC_MAKE (field , field_size );
150+ }
150151
151152 r = sd_journal_sendv (iovec , n_iovec );
152153 if (r < 0 )
@@ -172,17 +173,15 @@ static int move_file(PStoreEntry *pe, const char *subdir) {
172173}
173174
174175static int write_dmesg (const char * dmesg , size_t size , const char * id ) {
175- _cleanup_ (unlink_and_freep ) char * ofd_path = NULL ;
176- _cleanup_free_ char * tmp_path = NULL ;
176+ _cleanup_ (unlink_and_freep ) char * tmp_path = NULL ;
177+ _cleanup_free_ char * ofd_path = NULL ;
177178 _cleanup_close_ int ofd = -1 ;
178179 ssize_t wr ;
179180 int r ;
180181
181182 if (isempty (dmesg ) || size == 0 )
182183 return 0 ;
183184
184- /* log_info("Record ID %s", id); */
185-
186185 ofd_path = path_join (arg_archivedir , id , "dmesg.txt" );
187186 if (!ofd_path )
188187 return log_oom ();
@@ -198,17 +197,16 @@ static int write_dmesg(const char *dmesg, size_t size, const char *id) {
198197 r = link_tmpfile (ofd , tmp_path , ofd_path );
199198 if (r < 0 )
200199 return log_error_errno (r , "Failed to write temporary file %s: %m" , ofd_path );
201- ofd_path = mfree (ofd_path );
200+ tmp_path = mfree (tmp_path );
202201
203202 return 0 ;
204203}
205204
206205static void process_dmesg_files (PStoreList * list ) {
207206 /* Move files, reconstruct dmesg.txt */
208- PStoreEntry * pe ;
209- _cleanup_free_ char * dmesg = NULL ;
207+ _cleanup_free_ char * dmesg = NULL , * dmesg_id = NULL ;
210208 size_t dmesg_size = 0 ;
211- _cleanup_free_ char * dmesg_id = NULL ;
209+ PStoreEntry * pe ;
212210
213211 /* Handle each dmesg file: files processed in reverse
214212 * order so as to properly reconstruct original dmesg */
@@ -317,7 +315,7 @@ static void process_dmesg_files(PStoreList *list) {
317315static int list_files (PStoreList * list , const char * sourcepath ) {
318316 _cleanup_ (closedirp ) DIR * dirp = NULL ;
319317 struct dirent * de ;
320- int r = 0 ;
318+ int r ;
321319
322320 dirp = opendir (sourcepath );
323321 if (!dirp )
@@ -336,7 +334,7 @@ static int list_files(PStoreList *list, const char *sourcepath) {
336334 /* Now read contents of pstore file */
337335 r = read_full_file (ifd_path , & buf , & buf_size );
338336 if (r < 0 ) {
339- log_warning_errno (r , "Failed to read file %s: %m" , ifd_path );
337+ log_warning_errno (r , "Failed to read file %s, skipping : %m" , ifd_path );
340338 continue ;
341339 }
342340
@@ -352,14 +350,14 @@ static int list_files(PStoreList *list, const char *sourcepath) {
352350 };
353351 }
354352
355- return r ;
353+ return 0 ;
356354}
357355
358356static int run (int argc , char * argv []) {
359357 _cleanup_ (pstore_entries_reset ) PStoreList list = {};
360358 int r ;
361359
362- log_open ();
360+ log_setup_service ();
363361
364362 /* Ignore all parse errors */
365363 (void ) parse_config ();
0 commit comments