Changeset 5373:8da157c10483 in roaraudio for libroar/libroar.c
- Timestamp:
- 12/21/11 19:02:52 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note: See TracChangeset
for help on using the changeset viewer.