@@ -73,9 +73,10 @@ int main(int argc, const char* argv[])
73
73
bool no_daemon = false ;
74
74
unsigned long int port = 0 ;
75
75
unsigned long int num_threads = 0 ;
76
+ unsigned long int mode = 0 ;
76
77
char *endptr = NULL ;
77
78
if (argc > 4 ) {
78
- cout << " Usage: " << argv[0 ] << " [--no-daemon] [-p=port_number] [-n=number_threads]"
79
+ cout << " Usage: " << argv[0 ] << " [--no-daemon] [-p=port_number] [-m=unix_socket_mode] [- n=number_threads]"
79
80
<< endl;
80
81
exit (1 );
81
82
}
@@ -100,6 +101,19 @@ int main(int argc, const char* argv[])
100
101
}
101
102
cout << " port number [" << port << " ] found in cmdline" << endl;
102
103
continue ;
104
+ } else if (strncmp (argv[i], " -m=" , 3 ) == 0 ) {
105
+ if (strspn (argv[i] + 3 , " 0123456789" ) != strlen (argv[i] + 3 )) {
106
+ cout << " Please input valid socket mode" << endl;
107
+ exit (1 );
108
+ }
109
+ errno = 0 ;
110
+ mode = strtoul (argv[i] + 3 , &endptr, 8 );
111
+ if (errno || strlen (endptr) || (mode > UINT_MAX) ) {
112
+ cout << " Please input valid socket mode" << endl;
113
+ exit (1 );
114
+ }
115
+ cout << " socket mode [0" << oct << mode << dec << " ] found in cmdline" << endl;
116
+ continue ;
103
117
} else if (strncmp (argv[i], " -n=" , 3 ) == 0 ) {
104
118
if (strspn (argv[i] + 3 , " 0123456789" ) != strlen (argv[i] + 3 )) {
105
119
cout << " Please input valid thread number" << endl;
@@ -114,7 +128,7 @@ int main(int argc, const char* argv[])
114
128
cout << " thread number [" << num_threads << " ] found in cmdline" << endl;
115
129
continue ;
116
130
} else {
117
- cout << " Usage: " << argv[0 ] << " [--no-daemon] [-p=port_number] [-n=number_threads]"
131
+ cout << " Usage: " << argv[0 ] << " [--no-daemon] [-p=port_number] [-m=unix_socket_mode] [- n=number_threads]"
118
132
<< endl;
119
133
exit (1 );
120
134
}
@@ -123,7 +137,7 @@ int main(int argc, const char* argv[])
123
137
124
138
// Use the port number in QGS_CONFIG_FILE if no valid port number on
125
139
// command line
126
- if (port == 0 || num_threads == 0 ) {
140
+ if (port == 0 || num_threads == 0 || mode == 0 ) {
127
141
ifstream config_file (QGS_CONFIG_FILE);
128
142
if (config_file.is_open ()) {
129
143
string line;
@@ -155,6 +169,15 @@ int main(int argc, const char* argv[])
155
169
<< QGS_CONFIG_FILE << endl;
156
170
exit (1 );
157
171
}
172
+ } else if (!mode && name.compare (" socket_mode" ) == 0 ) {
173
+ errno = 0 ;
174
+ endptr = NULL ;
175
+ mode = strtoul (value, &endptr, 8 );
176
+ if (errno || strlen (endptr) || (mode > UINT_MAX)) {
177
+ cout << " Please input valid socket mode in "
178
+ << QGS_CONFIG_FILE << endl;
179
+ exit (1 );
180
+ }
158
181
} else if (!num_threads && name.compare (" number_threads" ) == 0 ) {
159
182
errno = 0 ;
160
183
endptr = NULL ;
@@ -206,6 +229,12 @@ int main(int argc, const char* argv[])
206
229
}
207
230
QGS_LOG_INFO (" About to create QgsServer with num_thread = %d\n " , (uint8_t )num_threads);
208
231
server = new QgsServer (io_service, ep, (uint8_t )num_threads);
232
+ /* Allow mode to be determined by umask by default,
233
+ * overriding only if an explicit mode is requested
234
+ */
235
+ if (!port && mode != 0 ) {
236
+ chmod (QGS_UNIX_SOCKET_FILE, mode);
237
+ }
209
238
QGS_LOG_INFO (" About to start main loop\n " );
210
239
io_service.run ();
211
240
QGS_LOG_INFO (" Quit main loop\n " );
0 commit comments