File: saveconfig.diff

package info (click to toggle)
tvtime 1.0.11-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,340 kB
  • sloc: ansic: 31,486; sh: 5,082; makefile: 571; pascal: 504; yacc: 316; asm: 249; perl: 192; cpp: 164; xml: 27; sed: 16
file content (200 lines) | stat: -rw-r--r-- 7,403 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
--- a/src/tvtimeconf.c
+++ b/src/tvtimeconf.c
@@ -34,6 +34,7 @@
 #include <errno.h>
 #include <libxml/parser.h>
 #include <math.h>
+#include <libgen.h>
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
@@ -596,7 +597,30 @@
     }
 
     xmlKeepBlanksDefault( 0 );
-    xmlSaveFormatFile( config_filename, doc, 1 );
+
+    if( create_file )
+    {
+        char *temp_config_filename = strdup( config_filename );
+
+        if( ! temp_config_filename )
+        {
+            fprintf( stderr, "strdup failed for config_filename %s\n", config_filename );
+            xmlFreeDoc( doc );
+            return 0;
+        }
+
+        mkdir_and_force_owner( dirname( temp_config_filename ), getuid(), getgid() );
+
+        free( temp_config_filename );
+    }
+
+    if( xmlSaveFormatFile( config_filename, doc, 1 ) == -1 )
+    {
+        fprintf( stderr, "xmlSaveFormatFile returned -1 for config_filename %s\n", config_filename );
+        xmlFreeDoc( doc );
+        return 0;
+    }
+
     if( create_file ) {
         if( chown( config_filename, getuid(), getgid() ) < 0 ) {
             lfprintf( stderr, _("Cannot change owner of %s: %s.\n"),
@@ -897,14 +921,6 @@
     ct->buttonmapmenu[ 4 ] = TVTIME_MENU_UP;
     ct->buttonmapmenu[ 5 ] = TVTIME_MENU_DOWN;
 
-    /* Make the ~/.tvtime directory every time on startup, to be safe. */
-    if( asprintf( &temp_dirname, "%s/.tvtime", getenv( "HOME" ) ) < 0 ) {
-        /* FIXME: Clean up ?? */
-        return 0;
-    }
-    mkdir_and_force_owner( temp_dirname, ct->uid, getgid() );
-    free( temp_dirname );
-
     /* First read in global settings. */
     asprintf( &base, "%s/tvtime.xml", CONFDIR );
     if( file_is_openable_for_read( base ) ) {
@@ -1113,6 +1129,7 @@
     int option_index = 0;
     int filename_specified = 0;
     int c;
+    int config_needs_saving = 0;
 
     if( argc == 1 ) {
         print_config_usage( argv );
@@ -1123,11 +1140,11 @@
 	    "aAhmMF:g:I:d::b::i::c:n::D:f::x:t::Ll::R::p::P::z::",
             long_options, &option_index )) != -1 ) {
         switch( c ) {
-        case 'a': ct->aspect = 1; break;
-        case 'A': ct->aspect = 0; break;
-        case 'm': ct->fullscreen = 1; break;
-        case 'L': ct->borderless = 1; break;
-        case 'M': ct->fullscreen = 0; break;
+        case 'a': ct->aspect = 1; config_needs_saving = 1; break;
+        case 'A': ct->aspect = 0; config_needs_saving = 1; break;
+        case 'm': ct->fullscreen = 1; config_needs_saving = 1; break;
+        case 'L': ct->borderless = 1; config_needs_saving = 1; break;
+        case 'M': ct->fullscreen = 0; config_needs_saving = 1; break;
         case 'F': if( ct->config_filename ) free( ct->config_filename );
                   filename_specified = 1;
                   ct->config_filename = expand_user_path( optarg );
@@ -1137,18 +1154,20 @@
                                 ct->config_filename );
                       conf_xml_parse( ct, ct->config_filename );
                   }
+                  // intentionally not : config_needs_saving = 1;
                   break;
         case 'x': if( ct->mixerdev ) { free( ct->mixerdev ); }
-                  ct->mixerdev = strdup( optarg ); break;
+                  ct->mixerdev = strdup( optarg ); config_needs_saving = 1; break;
         case 'g': if( ct->geometry ) { free( ct->geometry ); }
-                  ct->geometry = strdup( optarg ); break;
-        case 'I': ct->inputwidth = atoi( optarg ); break;
+                  ct->geometry = strdup( optarg ); config_needs_saving = 1; break;
+        case 'I': ct->inputwidth = atoi( optarg ); config_needs_saving = 1; break;
         case 'd': if( !optarg ) {
                       fprintf( stdout, "V4LDevice:%s\n",
                                config_get_v4l_device( ct ) );
                   } else {
                       free( ct->v4ldev );
                       ct->v4ldev = strdup( optarg );
+                      config_needs_saving = 1;
                   }
                   break;
         case 'b': if( !optarg ) {
@@ -1157,6 +1176,7 @@
                   } else {
                       free( ct->vbidev );
                       ct->vbidev = strdup( optarg );
+                      config_needs_saving = 1;
                   }
                   break;
         case 'i': if( !optarg ) {
@@ -1164,16 +1184,18 @@
                                config_get_inputnum( ct ) );
                   } else {
                       ct->inputnum = atoi( optarg );
+                      config_needs_saving = 1;
                   }
                   break;
         case 'c': ct->prev_channel = ct->start_channel;
-                  ct->start_channel = atoi( optarg ); break;
+                  ct->start_channel = atoi( optarg ); config_needs_saving = 1; break;
         case 't': if( !optarg ) {
                       fprintf( stdout, "XMLTVFile:%s\n",
                                config_get_xmltv_file( ct ) );
                   } else {
                       if( ct->xmltvfile ) free( ct->xmltvfile );
                       ct->xmltvfile = expand_user_path( optarg );
+                      config_needs_saving = 1;
                   }
                   break;
         case 'l': if( !optarg ) {
@@ -1182,6 +1204,7 @@
                   } else {
                       if( ct->xmltvlanguage ) free( ct->xmltvlanguage );
                       ct->xmltvlanguage = strdup( optarg );
+                      config_needs_saving = 1;
                   }
                   break;
         case 'n': if( !optarg ) {
@@ -1189,6 +1212,7 @@
                   } else {
                       free( ct->norm );
                       ct->norm = strdup( optarg );
+                      config_needs_saving = 1;
                   }
                   break;
         case 'f': if( !optarg ) {
@@ -1197,6 +1221,7 @@
                   } else {
                       free( ct->freq );
                       ct->freq = strdup( optarg );
+                      config_needs_saving = 1;
                   }
                   break;
         case 'R': if( !optarg ) {
@@ -1204,6 +1229,7 @@
                                config_get_priority( ct ) );
                   } else {
                       ct->priority = atoi( optarg );
+                      config_needs_saving = 1;
                   }
                   break;
         case 'p': if( !optarg ) {
@@ -1212,6 +1238,7 @@
                   } else {
                       free( ct->alsa_inputdev );
                       ct->alsa_inputdev = strdup( optarg );
+                      config_needs_saving = 1;
                   }
                   break;
         case 'P': if( !optarg ) {
@@ -1220,6 +1247,7 @@
                   } else {
                       free( ct->alsa_outputdev );
                       ct->alsa_outputdev = strdup( optarg );
+                      config_needs_saving = 1;
                   }
                   break;
 	case 'z': if( !optarg ) {
@@ -1227,6 +1255,7 @@
 			       config_get_alsa_latency( ct ) );
 		  } else {
 		      ct->alsa_latency = atoi( optarg );
+                      config_needs_saving = 1;
 		  }
 		  break;
         default:
@@ -1235,6 +1264,9 @@
         }
     }
 
+    if( ! config_needs_saving )
+        return 1;
+
     if( !filename_specified ) {
         char *fifofile = get_tvtime_fifo_filename( config_get_uid( ct ) );
         int fifofd;