name.c revision 6091827530d6dd43479d6709fb6e9f745c11e900
/*-*- Mode: C; c-basic-offset: 8 -*-*/
#include <assert.h>
#include <errno.h>
#include "set.h"
#include "name.h"
#include "macro.h"
#include "strv.h"
NameType name_type_from_string(const char *n) {
NameType t;
static const char* suffixes[_NAME_TYPE_MAX] = {
[NAME_SERVICE] = ".service",
[NAME_TIMER] = ".timer",
[NAME_SOCKET] = ".socket",
[NAME_MILESTONE] = ".milestone",
[NAME_DEVICE] = ".device",
[NAME_MOUNT] = ".mount",
[NAME_AUTOMOUNT] = ".automount",
[NAME_SNAPSHOT] = ".snapshot",
};
assert(n);
for (t = 0; t < _NAME_TYPE_MAX; t++)
return t;
return _NAME_TYPE_INVALID;
}
Name *n;
assert(m);
return NULL;
/* Not much initialization happening here at this time */
/* We don't link the name here, that is left for name_link() */
return n;
}
char **t;
int r;
assert(n);
goto fail;
return 0;
fail:
t--;
return r;
}
/* Detach from next 'bigger' objects */
char **t;
}
/* Free data and next 'smaller' objects */
/* FIXME: Other names pointing to us should probably drop their refs to us when we get destructed */
case NAME_SOCKET: {
unsigned i;
for (i = 0; i < s->n_fds; i++)
nointr_close(s->fds[i]);
break;
}
case NAME_DEVICE: {
break;
}
case NAME_MOUNT: {
break;
}
case NAME_AUTOMOUNT: {
break;
}
default:
;
}
}
return false;
case NAME_SERVICE: {
return
s->state == SERVICE_RUNNING ||
s->state == SERVICE_RELOAD_PRE ||
s->state == SERVICE_RELOAD ||
s->state == SERVICE_RELOAD_POST;
}
case NAME_TIMER: {
return
t->state == TIMER_WAITING ||
t->state == TIMER_RUNNING;
}
case NAME_SOCKET: {
return
s->state == SOCKET_LISTENING ||
s->state == SOCKET_RUNNING;
}
case NAME_MILESTONE:
case NAME_DEVICE:
case NAME_MOUNT:
case NAME_AUTOMOUNT: {
return
a->state == AUTOMOUNT_WAITING ||
a->state == AUTOMOUNT_RUNNING;
}
case NAME_SNAPSHOT:
case _NAME_TYPE_MAX:
case _NAME_TYPE_INVALID:
;
}
assert_not_reached("Unknown name type.");
return false;
}
int r;
assert(s);
if (!*s)
return -ENOMEM;
if (r != -EEXIST)
return r;
return 0;
}
int name_augment(Name *n) {
int r;
void* state;
assert(n);
/* Adds in the missing links to make all dependencies both-ways */
return r;
return r;
return r;
return r;
return r;
return r;
return r;
return r;
}