Changeset 5373:8da157c10483 in roaraudio
- Timestamp:
- 12/21/11 19:02:52 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroar/config.h
r5357 r5373 39 39 #include "libroar.h" 40 40 41 struct roar_connection; 42 41 43 // WorkAroundS: 42 44 #define ROAR_LIBROAR_CONFIG_WAS_NONE 0x00 … … 67 69 ROAR_LIBROAR_CONFIG_OPMODE_MS = 2, 68 70 #define ROAR_LIBROAR_CONFIG_OPMODE_MS ROAR_LIBROAR_CONFIG_OPMODE_MS 71 }; 72 73 struct roar_libroar_forkapi { 74 int (*prefork)(void ** context, void * userdata); 75 pid_t (*fork )(void ** context, void * userdata); 76 int (*failed )(void ** context, void * userdata); 77 int (*parent )(void ** context, void * userdata, pid_t child); 78 int (*child )(void ** context, void * userdata); 79 void * userdata; 69 80 }; 70 81 … … 115 126 #endif 116 127 enum roar_libroar_config_opmode opmode; 128 struct roar_libroar_forkapi * forkapi; 129 struct roar_vio_calls * (*connect_internal)(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout); 130 char * daemonimage; 131 int serverflags; 117 132 }; 118 133 … … 129 144 const char * roar_libroar_get_server(void) _LIBROAR_ATTR_USE_RESULT; 130 145 146 int roar_libroar_set_forkapi(struct roar_libroar_forkapi * api); 147 148 int roar_libroar_set_connect_internal(struct roar_vio_calls * (*func)(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout)); 149 131 150 void roar_libroar_nowarn(void); 132 151 void roar_libroar_warn(void); -
include/libroar/enumdev.h
r4708 r5373 40 40 41 41 #define ROAR_ENUM_FLAG_NONE 0x0000 /* no flags set */ 42 #define ROAR_ENUM_FLAG_DESC 0x0001 /* ask for server description 42 #define ROAR_ENUM_FLAG_DESC 0x0001 /* ask for server description 1 */ 43 43 #define ROAR_ENUM_FLAG_LOCATION 0x0002 /* ask for server location 1 */ 44 #define ROAR_ENUM_FLAG_NONBLOCK 0x0004 /* do not block 1*/44 #define ROAR_ENUM_FLAG_NONBLOCK 0x0004 /* do not block */ 45 45 #define ROAR_ENUM_FLAG_HARDNONBLOCK 0x0008 /* do even less block than NONBLOCK */ 46 #define ROAR_ENUM_FLAG_LOCALONLY 0x0010 /* only list local servers */ 46 47 /* 47 48 * 1 = This is a request. The result may include or not include the data anyway. 48 * This is only so the lib does not need to spend extra work ifdata is not needed.49 * This is only so the lib does not need to spend extra work when data is not needed. 49 50 */ 50 51 -
include/libroar/libroar.h
r5367 r5373 202 202 int roar_usleep(uint_least32_t t); 203 203 int roar_sleep(int t); 204 pid_t roar_fork(const struct roar_libroar_forkapi * api); 204 205 205 206 // call this function after we fork/exec()ed or similar. -
libroar/basic.c
r5369 r5373 64 64 } 65 65 66 // TODO: FIXME: we should move this into the config structure.67 66 if ( daemonimage == NULL ) 67 daemonimage = roar_libroar_get_config()->daemonimage; 68 69 // we keep this step to be compatible with older versions. 70 if ( daemonimage == NULL || *daemonimage == 0 ) { 68 71 daemonimage = getenv("ROAR_DAEMONIMAGE"); 72 if ( daemonimage != NULL ) { 73 ROAR_WARN("_start_server(*): Usage of $ROAR_DAEMONIMAGE is obsolete. Use ROAR_OPTIONS=daemonimage:..."); 74 } 75 } 69 76 70 77 if ( daemonimage == NULL || *daemonimage == 0 ) … … 76 83 } 77 84 78 r = fork();85 r = roar_fork(NULL); 79 86 80 87 if ( r == -1 ) { // error! 81 roar_err_from_errno(); 82 ROAR_ERR("roar_socket_open_fork(*): Can not fork: %s", strerror(errno)); 88 ROAR_ERR("_start_server(*): Can not fork: %s", roar_error2str(roar_error)); 83 89 close(socks[0]); 84 90 close(socks[1]); … … 106 112 107 113 // we are still alive? 108 ROAR_ERR(" roar_socket_open_fork(*): alive after exec(), that's bad!");114 ROAR_ERR("_start_server(*): alive after exec(), that's bad!"); 109 115 _exit(1); 110 116 } else { // we are the parent … … 121 127 return -1; 122 128 #else 123 ROAR_ERR(" roar_socket_open_fork(*): There is no UNIX Domain Socket support in win32, download a real OS.");129 ROAR_ERR("_start_server(*): There is no UNIX Domain Socket support in win32, download a real OS."); 124 130 return -1; 125 131 #endif 132 } 133 134 static int _connect_internal(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout) { 135 struct roar_libroar_config * config = roar_libroar_get_config(); 136 struct roar_vio_calls * vio; 137 138 if ( config->connect_internal != NULL ) { 139 vio = config->connect_internal(con, server, type, flags, timeout); 140 if ( vio == NULL ) 141 return -1; 142 143 con->viocon = vio; 144 con->flags |= ROAR_CON_FLAGS_VIO; 145 146 return 0; 147 } 148 149 roar_err_set(ROAR_ERROR_BADHOST); 150 return -1; 126 151 } 127 152 … … 153 178 } else if ( !strcmp(server, "+fork") || !strncmp(server, "+fork=", 6) ) { 154 179 return _start_server(con, server, type, flags, timeout); 180 } else if ( !strcmp(server, "+internal") || !strncmp(server, "+internal=", 10) ) { 181 return _connect_internal(con, server, type, flags, timeout); 155 182 } 156 183 … … 346 373 #ifdef ROAR_HAVE_LIBSLP 347 374 if ( !(config->workaround.workarounds & ROAR_LIBROAR_CONFIG_WAS_NO_SLP) && 348 !(flags & ROAR_ENUM_FLAG_NONBLOCK) 375 !(flags & ROAR_ENUM_FLAG_NONBLOCK) && 376 !(flags & ROAR_ENUM_FLAG_LOCALONLY) 349 377 ) { 350 378 if ( (server = roar_slp_find_roard(0)) != NULL ) { … … 391 419 392 420 int roar_connect (struct roar_connection * con, const char * server, int flags, uint_least32_t timeout) { 421 struct roar_libroar_config * config = roar_libroar_get_config(); 422 393 423 if ( con == NULL ) { 394 424 roar_err_set(ROAR_ERROR_FAULT); … … 400 430 401 431 roar_err_set(ROAR_ERROR_UNKNOWN); 402 if ( roar_connect_raw(con, server, flags, timeout) == -1 ) 403 return -1; 404 432 if ( roar_connect_raw(con, server, flags | config->serverflags, timeout) == -1 ) 433 return -1; 434 435 // TODO: this should be moved to be within _connect_server() so it also stores server names of auto located servers. 405 436 if ( server != NULL ) { 406 437 con->server_name = roar_mm_strdup(server); -
libroar/cdrom.c
r5289 r5373 64 64 } 65 65 66 if ( (pid = fork()) ==-1 ) {66 if ( (pid = roar_fork(NULL)) == (pid_t)-1 ) { 67 67 return -1; 68 68 } -
libroar/config.c
r5357 r5373 50 50 51 51 #ifdef ROAR_SUPPORT_TRAP 52 config.trap_policy = ROAR_TRAP_IGNORE;52 config.trap_policy = ROAR_TRAP_IGNORE; 53 53 #endif 54 config.opmode = ROAR_LIBROAR_CONFIG_OPMODE_NORMAL; 55 config.server = NULL; 56 config.authfile = NULL; 54 config.opmode = ROAR_LIBROAR_CONFIG_OPMODE_NORMAL; 55 config.server = NULL; 56 config.authfile = NULL; 57 config.forkapi = NULL; 58 config.connect_internal = NULL; 59 config.daemonimage = NULL; 57 60 58 61 if ( home != NULL ) { 59 snprintf(authfile, 1023, "%s/.roarauth", home);60 authfile[ 1023]= 0;62 snprintf(authfile, sizeof(authfile)-1, "%s/.roarauth", home); 63 authfile[sizeof(authfile)-1] = 0; 61 64 config.authfile = authfile; 62 65 config.serversfile = NULL; … … 304 307 } else if ( !strcmp(k, "x11-display") ) { 305 308 config->x11.display = v; 309 } else if ( !strcmp(k, "daemonimage") ) { 310 config->daemonimage = v; 311 } else if ( !strcmp(k, "serverflags") ) { 312 if ( !strcmp(v, "nonblock") ) { 313 config->serverflags |= ROAR_ENUM_FLAG_NONBLOCK; 314 } else if ( !strcmp(v, "hardnonblock") ) { 315 config->serverflags |= ROAR_ENUM_FLAG_HARDNONBLOCK; 316 } else if ( !strcmp(v, "localonly") ) { 317 config->serverflags |= ROAR_ENUM_FLAG_LOCALONLY; 318 } else { 319 ROAR_WARN("roar_libroar_config_parse(*): Unknown serverflag: %s", v); 320 } 306 321 } else { 307 322 ROAR_WARN("roar_libroar_config_parse(*): Unknown option: %s", k); … … 389 404 } 390 405 406 int roar_libroar_set_forkapi(struct roar_libroar_forkapi * api) { 407 roar_libroar_get_config_ptr()->forkapi = api; 408 return 0; 409 } 410 411 int roar_libroar_set_connect_internal(struct roar_vio_calls * (*func)(struct roar_connection * con, const char * server, int type, int flags, uint_least32_t timeout)) { 412 roar_libroar_get_config_ptr()->connect_internal = func; 413 return 0; 414 } 415 391 416 void roar_libroar_nowarn(void) { 392 417 roar_libroar_get_config_ptr()->nowarncounter++; -
libroar/enumdev.c
r5324 r5373 105 105 (void)flags, (void)dir, (void)socktype; 106 106 107 if ( maxlen < 11 ) 108 return -1; 109 110 new = roar_libroar_get_server(); 111 _add(new); 112 113 new = getenv("ROAR_SERVER"); 114 _add(new); 107 if ( maxlen < 12 ) 108 return -1; 109 110 // We can not yet test if those servers are local or reachable via network so 111 // we skip them for now. 112 // TODO: test those servers. 113 if ( !(flags & ROAR_ENUM_FLAG_LOCALONLY) ) { 114 new = roar_libroar_get_server(); 115 _add(new); 116 117 new = getenv("ROAR_SERVER"); 118 _add(new); 115 119 116 120 #ifdef ROAR_HAVE_LIBX11 117 if ( (x11con = roar_x11_connect(NULL)) != NULL ) { 118 new = roar_x11_get_prop(x11con, "ROAR_SERVER"); 119 _add(new); 120 roar_x11_disconnect(x11con); 121 } 122 #endif 123 124 new = getenv("SSH_CLIENT"); 125 if ( new == NULL ) 126 new = getenv("SSH_CONNECTION"); 127 128 if ( new != NULL ) { 129 ssh_buf = roar_mm_strdup(new); 130 if ( ssh_buf != NULL ) { 131 tmp = strstr(ssh_buf, " "); 132 if ( tmp == NULL ) { 133 // invalid format. 134 roar_mm_free(ssh_buf); 135 } else { 136 *tmp = 0; 137 servers[ret++] = ssh_buf; 121 if ( (x11con = roar_x11_connect(NULL)) != NULL ) { 122 new = roar_x11_get_prop(x11con, "ROAR_SERVER"); 123 _add(new); 124 roar_x11_disconnect(x11con); 125 } 126 #endif 127 128 new = getenv("SSH_CLIENT"); 129 if ( new == NULL ) 130 new = getenv("SSH_CONNECTION"); 131 132 if ( new != NULL ) { 133 ssh_buf = roar_mm_strdup(new); 134 if ( ssh_buf != NULL ) { 135 tmp = strstr(ssh_buf, " "); 136 if ( tmp == NULL ) { 137 // invalid format. 138 roar_mm_free(ssh_buf); 139 } else { 140 *tmp = 0; 141 servers[ret++] = ssh_buf; 142 } 138 143 } 139 144 } 140 }141 145 142 146 #if !defined(ROAR_TARGET_WIN32) && !defined(ROAR_TARGET_MICROCONTROLLER) 143 if ( (i = readlink("/etc/roarserver", buf, sizeof(buf)-1)) != -1 ) { 144 buf[i] = 0; 145 _add(buf); 146 } 147 #endif 147 if ( (i = readlink("/etc/roarserver", buf, sizeof(buf)-1)) != -1 ) { 148 buf[i] = 0; 149 _add(buf); 150 } 151 #endif 152 } 148 153 149 154 if ( (new = roar_env_get_home(0)) != NULL ) { … … 158 163 servers[ret++] = roar_mm_strdup("+abstract"); 159 164 servers[ret++] = roar_mm_strdup("/tmp/muroard"); 165 servers[ret++] = roar_mm_strdup("/dev/roar"); 160 166 161 167 return ret; … … 290 296 291 297 static struct locmed _libroar_locmod[] = { 292 {ROAR_ENUM_FLAG_NONBLOCK|ROAR_ENUM_FLAG_HARDNONBLOCK , _esl_defaults},293 {ROAR_ENUM_FLAG_NONE, _esl_slp},298 {ROAR_ENUM_FLAG_NONBLOCK|ROAR_ENUM_FLAG_HARDNONBLOCK|ROAR_ENUM_FLAG_LOCALONLY, _esl_defaults}, 299 {ROAR_ENUM_FLAG_NONE, _esl_slp}, 294 300 #ifdef ROAR_HAVE_FOPEN 295 {ROAR_ENUM_FLAG_NONBLOCK, _esl_neighbours}301 {ROAR_ENUM_FLAG_NONBLOCK, _esl_neighbours} 296 302 #endif 297 303 }; 298 304 299 305 struct roar_server * roar_enum_servers(int flags, int dir, int socktype) { 306 struct roar_libroar_config * config = roar_libroar_get_config(); 300 307 struct roar_server * ret = NULL; 301 308 struct roar_server * c; … … 304 311 size_t i, cp, unic; 305 312 ssize_t r; 306 int testflags = flags;313 int testflags; 307 314 int is_uniq; 315 316 flags |= config->serverflags; 317 testflags = flags; 308 318 309 319 if ( flags & ROAR_ENUM_FLAG_HARDNONBLOCK ) -
libroar/libroar.c
r5270 r5373 154 154 } 155 155 156 static pid_t _libroar_fork(void ** context, void * userdata) { 157 pid_t ret; 158 (void)context, (void)userdata; 159 ret = fork(); 160 if ( ret == -1 ) 161 roar_err_from_errno(); 162 return ret; 163 } 164 165 static const struct roar_libroar_forkapi _libroar_forkapi = { 166 .prefork = NULL, 167 .fork = _libroar_fork, 168 .failed = NULL, 169 .parent = NULL, 170 .child = NULL, 171 .userdata = NULL 172 }; 173 174 pid_t roar_fork(const struct roar_libroar_forkapi * api) { 175 void * context = NULL; 176 int err; 177 pid_t ret; 178 179 if ( api == NULL ) 180 api = &_libroar_forkapi; 181 182 if ( api->fork == NULL ) { 183 roar_err_set(ROAR_ERROR_INVAL); 184 return -1; 185 } 186 187 if ( api->prefork != NULL ) { 188 if ( api->prefork(&context, api->userdata) != 0 ) { 189 if ( api->failed != NULL ) 190 api->failed(&context, api->userdata); 191 192 if ( context != NULL ) { 193 err = roar_error; 194 roar_mm_free(context); 195 roar_error = err; 196 } 197 return (pid_t)-1; 198 } 199 } 200 201 if ( (ret = api->fork(&context, api->userdata)) == (pid_t)-1 ) { 202 if ( api->failed != NULL ) 203 api->failed(&context, api->userdata); 204 205 if ( context != NULL ) { 206 err = roar_error; 207 roar_mm_free(context); 208 roar_error = err; 209 } 210 return (pid_t)-1; 211 } 212 213 if ( ret == (pid_t)0 ) { 214 if ( api->child != NULL ) 215 api->child(&context, api->userdata); 216 } else { 217 if ( api->parent != NULL ) 218 api->parent(&context, api->userdata, ret); 219 } 220 221 if ( context != NULL ) { 222 err = roar_error; 223 roar_mm_free(context); 224 roar_error = err; 225 } 226 227 return ret; 228 } 229 156 230 int roar_reset(enum roar_reset what) { 157 231 char c; -
libroar/pinentry.c
r5270 r5373 88 88 } 89 89 90 pe->pid = fork();90 pe->pid = roar_fork(NULL); 91 91 92 92 switch (pe->pid) { -
libroar/socket.c
r5369 r5373 1154 1154 #endif 1155 1155 1156 r = fork();1156 r = roar_fork(NULL); 1157 1157 1158 1158 if ( r == -1 ) { // error! -
libroar/vio_cmd.c
r5364 r5373 159 159 } 160 160 161 child->pid = fork();161 child->pid = roar_fork(NULL); 162 162 163 163 switch (child->pid) {
Note: See TracChangeset
for help on using the changeset viewer.