32#define LOG(kind, ...) GNUNET_log_from (kind, "util", __VA_ARGS__)
34#define LOG_STRERROR(kind, syscall) \
35 GNUNET_log_from_strerror (kind, "util", syscall)
42static char *wait_filename;
47static FILE *wait_file;
56#define MAX_NOTIFY_QUEUE 1024
294 socklen_t *saddrlens,
295 const char *unixpath,
299 struct sockaddr_un *un;
302 un->sun_family = AF_UNIX;
306 un->sun_path[0] =
'\0';
308#if HAVE_SOCKADDR_UN_SUN_LEN
309 un->sun_len = (u_char)
sizeof(
struct sockaddr_un);
311 *saddrs = (
struct sockaddr *) un;
312 *saddrlens =
sizeof(
struct sockaddr_un);
344 struct sockaddr ***addrs,
345 socklen_t **addr_lens)
349 unsigned long long port;
351 struct addrinfo hints;
352 struct addrinfo *
res;
353 struct addrinfo *pos;
354 struct addrinfo *next;
359 struct sockaddr **saddrs;
360 socklen_t *saddrlens;
378 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
386 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
407 _ (
"Require valid port number for service `%s' in configuration!\n"),
413 _ (
"Require valid port number for service `%s' in configuration!\n"),
433 (0 < strlen (unixpath)) )
436 struct sockaddr_un s_un;
438 if (strlen (unixpath) >=
sizeof(s_un.sun_path))
441 _ (
"UNIXPATH `%s' too long, maximum length is %llu\n"),
443 (
unsigned long long)
sizeof(s_un.sun_path));
450 "USE_ABSTRACT_SOCKETS");
458 if (NULL != unixpath)
463 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
473 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
487 if ((0 ==
port) && (NULL == unixpath))
495 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
508 *addr_lens = saddrlens;
512 if (NULL != hostname)
515 "Resolving `%s' since that is where `%s' will bind to.\n",
518 memset (&hints, 0,
sizeof(
struct addrinfo));
520 hints.ai_family = AF_INET;
521 hints.ai_protocol = IPPROTO_TCP;
522 if ((0 != (
ret = getaddrinfo (hostname, NULL, &hints, &
res))) ||
526 _ (
"Failed to resolve `%s': %s\n"),
535 while (NULL != (pos = next))
538 if ((disablev6) && (pos->ai_family == AF_INET6))
545 _ (
"Failed to find %saddress for `%s'.\n"),
546 disablev6 ?
"IPv4 " :
"",
554 if (NULL != unixpath)
559 if (NULL != unixpath)
565 while (NULL != (pos = next))
568 if ((disablev6) && (AF_INET6 == pos->ai_family))
570 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
572 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
575 "Service `%s' will bind to `%s'\n",
578 if (AF_INET == pos->ai_family)
580 GNUNET_assert (
sizeof(
struct sockaddr_in) == pos->ai_addrlen);
581 saddrlens[i] = pos->ai_addrlen;
584 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
589 GNUNET_assert (
sizeof(
struct sockaddr_in6) == pos->ai_addrlen);
590 saddrlens[i] = pos->ai_addrlen;
593 ((
struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (
port);
608 if (NULL != unixpath)
613 if (NULL != unixpath)
618 saddrlens[i] =
sizeof(
struct sockaddr_in);
620#if HAVE_SOCKADDR_IN_SIN_LEN
621 ((
struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i];
623 ((
struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
624 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
630 if (NULL != unixpath)
635 if (NULL != unixpath)
640 saddrlens[i] =
sizeof(
struct sockaddr_in6);
642#if HAVE_SOCKADDR_IN_SIN_LEN
643 ((
struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0];
645 ((
struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6;
646 ((
struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (
port);
648 saddrlens[i] =
sizeof(
struct sockaddr_in);
650#if HAVE_SOCKADDR_IN_SIN_LEN
651 ((
struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1];
653 ((
struct sockaddr_in *) saddrs[i])->sin_family = AF_INET;
654 ((
struct sockaddr_in *) saddrs[i])->sin_port = htons (
port);
659 *addr_lens = saddrlens;
709 "Sending status %u of service `%s' to client\n",
712 namelen = strlen (
name) + 1;
716 msg->status = htonl ((uint32_t) (
status));
752 bool is_simple_service;
768 if (NULL != sli->accept_task)
771 sli->accept_task = NULL;
804 while (NULL != (optpos = strstr (fin_options,
"{}")))
814 fin_options = new_options;
836 const char *service_type = NULL;
843 is_simple_service =
false;
850 (0 == strcasecmp (service_type,
852 is_simple_service =
true;
856 if (is_simple_service)
867 "Starting simple service `%s' using binary `%s'\n",
889 "Starting service `%s' using binary `%s' and configuration `%s'\n",
960 if (NULL == sl->
proc)
963 "Failed to start service `%s'\n",
974 "Starting service `%s'\n",
1009 if (0 == strcasecmp (sl->
name,
name))
1055 switch (sa->sa_family)
1075 errno = EAFNOSUPPORT;
1081 _ (
"Unable to create socket for service `%s': %s\n"),
1095 if ((sa->sa_family == AF_INET6) &&
1104 if (AF_UNIX == sa->sa_family)
1112 "Unable to bind listening socket for service `%s' to address `%s': %s\n"),
1120 if ((AF_UNIX == sa->sa_family)
1123 && (
'\0' != ((
const struct sockaddr_un *) sa)->sun_path[0])
1149 _ (
"ARM now monitors connections to service `%s' at `%s'\n"),
1212 const char *servicename;
1214 uint64_t request_id;
1217 servicename = (
const char *) &amsg[1];
1237 if (NULL != sl->
proc)
1291 const char *servicename;
1292 uint64_t request_id;
1295 servicename = (
const char *) &amsg[1];
1297 _ (
"Preparing to stop `%s'\n"),
1300 if (0 == strcasecmp (servicename,
"arm"))
1336 if (NULL == sl->
proc)
1346 "Sending kill signal to service `%s', waiting for process to die.\n",
1370pool_write (
char *pool_start,
size_t pool_size,
size_t *pool_pos,
char *str)
1372 size_t next_pos = (*pool_pos) + strlen (str) + 1;
1374 if (next_pos > pool_size)
1376 memcpy (pool_start + *pool_pos, str, strlen (str) + 1);
1377 *pool_pos = next_pos;
1410 pool_size += strlen (sl->
name) + 1;
1411 pool_size += strlen (sl->
binary) + 1;
1415 extra_size = pool_size + (count *
sizeof (
struct
1421 msg->count = htons (count);
1424 pool_start = (
char *) (ssm + count);
1429 ssm->
name_index = htons ((uint16_t) pool_pos);
1435 if (NULL == sl->
proc)
1527 for (
res = 0, i = run_head; NULL != i; i = i->
next,
res++)
1572 while (NULL != (pos = nxt))
1575 if (NULL != pos->
proc)
1592 "Delaying shutdown, have %u children still running\n",
1629 _ (
"Restarting service `%s'.\n"),
1651 lowestRestartDelay =
1661 "Will restart process in %s\n",
1685 const char *statstr;
1690 unsigned long statusCode;
1701 while (NULL != (pos = next))
1705 if (NULL == pos->
proc)
1712 if (NULL != wait_file)
1726 statusCode = WEXITSTATUS (
status);
1728 else if (WIFSIGNALED (
status))
1731 statusCode = WTERMSIG (
status);
1733 else if (WIFSTOPPED (
status))
1736 statusCode = WSTOPSIG (
status);
1739 else if (WIFCONTINUED (
status))
1753 double utime = ru.ru_utime.tv_sec + (ru.ru_utime.tv_usec / 10e6);
1754 double stime = ru.ru_stime.tv_sec + (ru.ru_stime.tv_usec / 10e6);
1756 "%s(%u) %.3f %.3f %llu %llu %llu %llu %llu\n",
1761 (
unsigned long long) ru.ru_maxrss,
1762 (
unsigned long long) ru.ru_inblock,
1763 (
unsigned long long) ru.ru_oublock,
1764 (
unsigned long long) ru.ru_nvcsw,
1765 (
unsigned long long) ru.ru_nivcsw);
1780 statstr =
_ (
"exit");
1781 statcode = statusCode;
1785 statstr =
_ (
"signal");
1786 statcode = statusCode;
1790 statstr =
_ (
"unknown");
1796 _ (
"Service `%s' took %s to terminate\n"),
1823 _ (
"Service `%s' terminated normally, will restart at any time\n"),
1840 _ (
"Service `%s' terminated with status %s/%d, will restart in %s\n"),
1850 unsigned int minutes;
1885 "Delaying shutdown after child's death, still have %u children\n",
1898 int old_errno = errno;
1926 struct sockaddr **addrs;
1927 socklen_t *addr_lens;
1931 if (0 == strcasecmp (section,
"arm"))
2030 for (
unsigned int i = 0; i < (
unsigned int)
ret; i++)
2075 if (sl->killing_client == client)
2076 sl->killing_client = NULL;
2134 "RESOURCE_DIAGNOSTICS",
2137 wait_file = fopen (wait_filename,
"w");
2138 if (NULL == wait_file)
2164 "START_SYSTEM_SERVICES");
2167 "START_USER_SERVICES");
2179 "START_SYSTEM_SERVICES"))
2183 "START_USER_SERVICES"))
2194 "Please enable either START_USER_SERVICES or START_SYSTEM_SERVICES\n");
2263 if (NULL != wait_file)
2268 if (NULL != wait_filename)
2271 wait_filename = NULL;
2282#if defined(__linux__) && defined(__GLIBC__)
2286GNUNET_ARM_memory_init (
void);
2292GNUNET_ARM_memory_init (
void)
2294 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
2295 mallopt (M_TOP_PAD, 1 * 1024);
struct GNUNET_GETOPT_CommandLineOption options[]
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MQ_Handle * mq
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static struct GNUNET_SIGNAL_Context * shc_chld
static int start
Set if we are to start default services (including ARM).
static int monitor
Monitor ARM activity.
static int list
Set if we should print a list of currently running services.
static int ret
Final status code.
static uint16_t port
Port number.
const struct GNUNET_CONFIGURATION_Handle * config
static char * name
Name (label) of the records to list.
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_NETWORK_Handle * ls
Listen socket for STUN processing.
static int status
The program status; 0 for success.
static int result
Global testing status.
static struct GNUNET_SCHEDULER_Task * child_restart_task
ID of task called whenever the timeout for restarting a child expires.
static void delayed_restart_task(void *cls)
Task run whenever it is time to restart a child that died.
static struct ServiceList * running_head
List of running services.
static void trigger_shutdown(void *cls)
Start a shutdown sequence.
static void start_process(struct ServiceList *sl, struct GNUNET_SERVICE_Client *client, uint64_t request_id)
Actually start the process for the given service.
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *serv)
Process arm requests.
static void broadcast_status(const char *name, enum GNUNET_ARM_ServiceMonitorStatus status, struct GNUNET_SERVICE_Client *unicast)
Tell all clients about status change of a service.
static void free_service(struct ServiceList *sl)
Remove and free an entry in the service list.
#define MAX_NOTIFY_QUEUE
How many messages do we queue up at most for optional notifications to a client? (this can cause noti...
static char * prefix_command
Command to prepend to each actual command.
static void handle_stop(void *cls, const struct GNUNET_ARM_Message *amsg)
Handle STOP-message.
static char * final_option
Option to append to each actual command.
static void add_unixpath(struct sockaddr **saddrs, socklen_t *saddrlens, const char *unixpath, int abstract)
Add the given UNIX domain path as an address to the list (as the first entry).
static int global_ret
Return value from main.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static int start_user
Are we starting user services?
static void maint_child_death(void *cls)
Task triggered whenever we receive a SIGCHLD (child process died).
static unsigned int list_count(struct ServiceList *run_head)
Count how many services are still active.
static struct GNUNET_SCHEDULER_Task * child_death_task
ID of task called whenever we get a SIGCHILD.
static int start_system
Are we starting system services?
static int check_stop(void *cls, const struct GNUNET_ARM_Message *amsg)
Check STOP-message.
static int in_shutdown
Are we in shutdown mode?
static void shutdown_task(void *cls)
Task run for shutdown.
static void handle_test(void *cls, const struct GNUNET_MessageHeader *message)
Handle TEST-message by sending back TEST.
static void setup_service(void *cls, const char *section)
Setup our service record for the given section in the configuration file (assuming the section is for...
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
A client connected, mark as a monitoring client.
static struct GNUNET_DISK_PipeHandle * sigpipe
Pipe used to communicate shutdown via signal.
static int get_server_addresses(const char *service_name, const struct GNUNET_CONFIGURATION_Handle *cfg_, struct sockaddr ***addrs, socklen_t **addr_lens)
Get the list of addresses that a server for the given service should bind to.
static void sighandler_child_death()
Signal handler called for SIGCHLD.
static void accept_connection(void *cls)
First connection has come to the listening socket associated with the service, create the service in ...
static void handle_start(void *cls, const struct GNUNET_ARM_Message *amsg)
Handle START-message.
static void do_shutdown()
We are done with everything.
static struct ServiceList * running_tail
List of running services.
static void handle_list(void *cls, const struct GNUNET_ARM_Message *request)
Handle LIST-message.
static void create_listen_socket(struct sockaddr *sa, socklen_t addr_len, struct ServiceList *sl)
Creating a listening socket for each of the service's addresses and wait for the first incoming conne...
int main(int argc, char *const *argv)
The main function for the arm service.
static void handle_monitor(void *cls, const struct GNUNET_MessageHeader *message)
Handle MONITOR-message.
static void signal_result(struct GNUNET_SERVICE_Client *client, const char *name, uint64_t request_id, enum GNUNET_ARM_Result result)
Signal our client that we will start or stop the service.
#define LOG_STRERROR(kind, syscall)
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
A client disconnected, clean up associated state.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static struct ServiceList * find_service(const char *name)
Find the process with the given service name in the given list and return it.
static int pool_write(char *pool_start, size_t pool_size, size_t *pool_pos, char *str)
Write a string to a string pool.
static struct GNUNET_NotificationContext * notifier
Context for notifications we need to send to our clients.
static int check_start(void *cls, const struct GNUNET_ARM_Message *amsg)
Check START-message.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static char * service_name
Option -s: service name (hash to get service descriptor)
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
struct GNUNET_PQ_ResultSpec __attribute__
Constants for network protocols.
GNUNET_ARM_ServiceMonitorStatus
Statuses of services.
GNUNET_ARM_Result
Replies to ARM requests.
@ GNUNET_ARM_SERVICE_STATUS_FINISHED
The service was started, but then exited normally.
@ GNUNET_ARM_SERVICE_STATUS_FAILED
The service has previously failed, and will be restarted.
@ GNUNET_ARM_SERVICE_STATUS_STOPPED
Service is stopped.
@ GNUNET_ARM_SERVICE_STATUS_STOPPING
The service was started, and we're currently waiting for it to be stopped.
@ GNUNET_ARM_SERVICE_STATUS_STARTED
Service has been started and is currently running.
@ GNUNET_ARM_SERVICE_STOPPING
Service stopping was initiated.
@ GNUNET_ARM_SERVICE_STOPPED
Service was stopped.
@ GNUNET_ARM_SERVICE_STARTING
Service starting was initiated.
@ GNUNET_ARM_SERVICE_MONITORING_STARTED
Dummy message.
@ GNUNET_ARM_RESULT_IS_NOT_KNOWN
Asked to start or stop a service, but it's not known.
@ GNUNET_ARM_RESULT_IS_STOPPED_ALREADY
Asked to stop it, but it's already stopped.
@ GNUNET_ARM_RESULT_STARTING
Service starting was initiated.
@ GNUNET_ARM_RESULT_IS_STARTED_ALREADY
Asked to start it, but it's already started.
@ GNUNET_ARM_RESULT_STOPPING
ARM stopping was initiated (there's no "stopped" for ARM itself).
@ GNUNET_ARM_RESULT_IS_STOPPING_ALREADY
Asked to stop it, but it's already stopping.
@ GNUNET_ARM_RESULT_STOPPED
Service was stopped (never sent for ARM itself).
@ GNUNET_ARM_RESULT_START_FAILED
Tried to start a service, but that failed for some reason.
@ GNUNET_ARM_RESULT_IN_SHUTDOWN
Asked to start something, but ARM is shutting down and can't comply.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CONFIGURATION_iterate_sections(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CONFIGURATION_SectionIterator iter, void *iter_cls)
Iterate over all sections in the configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
char * GNUNET_CONFIGURATION_expand_dollar(const struct GNUNET_CONFIGURATION_Handle *cfg, char *orig)
Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" where either in the "PATHS" section or...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_have_value(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Test if we have a value for a particular option.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_choice(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *const *choices, const char **value)
Get a configuration value that should be in a set of predefined strings.
const struct GNUNET_DISK_FileHandle * GNUNET_DISK_pipe_handle(const struct GNUNET_DISK_PipeHandle *p, enum GNUNET_DISK_PipeEnd n)
Get the handle to a particular pipe end.
void GNUNET_DISK_fix_permissions(const char *fn, int require_uid_match, int require_gid_match)
Update POSIX permissions mask of a file on disk.
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
struct GNUNET_DISK_PipeHandle * GNUNET_DISK_pipe(enum GNUNET_DISK_PipeFlags pf)
Creates an interprocess channel.
enum GNUNET_GenericReturnValue GNUNET_DISK_pipe_close(struct GNUNET_DISK_PipeHandle *p)
Closes an interprocess channel.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
@ GNUNET_DISK_PF_NONE
No special options, use non-blocking read/write operations.
@ GNUNET_DISK_PIPE_END_WRITE
The writing-end of a pipe.
@ GNUNET_DISK_PIPE_END_READ
The reading-end of a pipe.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log(kind,...)
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_SCHEDULER_PRIORITY_IDLE
Run when otherwise idle.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
int GNUNET_NETWORK_get_fd(const struct GNUNET_NETWORK_Handle *desc)
Return file descriptor for this network handle.
char * GNUNET_NETWORK_shorten_unixpath(char *unixpath)
Given a unixpath that is too long (larger than UNIX_PATH_MAX), shorten it to an acceptable length whi...
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
void GNUNET_NETWORK_unix_precheck(const struct sockaddr_un *un)
If services crash, they can leave a unix domain socket file on the disk.
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
struct GNUNET_OS_Process * GNUNET_OS_start_process_s(enum GNUNET_OS_InheritStdioFlags std_inheritance, const int *lsocks, const char *filename,...)
Start a process.
pid_t GNUNET_OS_process_get_pid(struct GNUNET_OS_Process *proc)
Get the pid of the process in question.
GNUNET_OS_ProcessStatusType
Process status types.
void GNUNET_OS_process_destroy(struct GNUNET_OS_Process *proc)
Cleans up process structure contents (OS-dependent) and deallocates it.
int GNUNET_OS_process_kill(struct GNUNET_OS_Process *proc, int sig)
Sends a signal to the process.
enum GNUNET_GenericReturnValue GNUNET_OS_process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process.
@ GNUNET_OS_INHERIT_STD_OUT_AND_ERR
When these flags are set, the child process will inherit stdout and stderr of the parent.
@ GNUNET_OS_USE_PIPE_CONTROL
Should a pipe be used to send signals to the child?
@ GNUNET_OS_PROCESS_SIGNALED
The process was killed by a signal.
@ GNUNET_OS_PROCESS_EXITED
The process exited with a return code.
@ GNUNET_OS_PROCESS_UNKNOWN
The process is not known to the OS (or at least not one of our children).
@ GNUNET_OS_PROCESS_STOPPED
The process is paused (but could be resumed).
@ GNUNET_OS_PROCESS_RUNNING
The process is still running.
#define GNUNET_MESSAGE_TYPE_ARM_STOP
Request to ARM to stop a service.
#define GNUNET_MESSAGE_TYPE_ARM_RESULT
Response from ARM.
#define GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT
Response from ARM for listing currently running services.
#define GNUNET_MESSAGE_TYPE_ARM_TEST
Test if ARM service is online.
#define GNUNET_MESSAGE_TYPE_ARM_STATUS
Status update from ARM.
#define GNUNET_MESSAGE_TYPE_ARM_START
Request to ARM to start a service.
#define GNUNET_MESSAGE_TYPE_ARM_LIST
Request to ARM to list all currently running services.
#define GNUNET_MESSAGE_TYPE_ARM_MONITOR
Request to ARM to notify client of service status changes.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_file(struct GNUNET_TIME_Relative delay, const struct GNUNET_DISK_FileHandle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
void GNUNET_SERVICE_shutdown(struct GNUNET_SERVICE_Handle *sh)
Explicitly stops the service.
void GNUNET_SERVICE_client_mark_monitor(struct GNUNET_SERVICE_Client *c)
Set the 'monitor' flag on this client.
void GNUNET_SERVICE_client_persist(struct GNUNET_SERVICE_Client *c)
Set the persist option on this client.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
int GNUNET_SERVICE_run_(int argc, char *const *argv, const char *service_name, enum GNUNET_SERVICE_Options options, GNUNET_SERVICE_InitCallback service_init_cb, GNUNET_SERVICE_ConnectHandler connect_cb, GNUNET_SERVICE_DisconnectHandler disconnect_cb, void *cls, const struct GNUNET_MQ_MessageHandler *handlers)
Creates the "main" function for a GNUnet service.
@ GNUNET_SERVICE_OPTION_MANUAL_SHUTDOWN
Do not trigger server shutdown on signal at all; instead, allow for the user to terminate the server ...
@ GNUNET_SERVICE_OPTION_CLOSE_LSOCKS
Instead of listening on lsocks passed by the parent, close them after opening our own listen socket(s...
struct GNUNET_SIGNAL_Context * GNUNET_SIGNAL_handler_install(int signal, GNUNET_SIGNAL_Handler handler)
Install a signal handler that will be run if the given signal is received.
void GNUNET_SIGNAL_handler_uninstall(struct GNUNET_SIGNAL_Context *ctx)
Uninstall a previously installed signal handler.
size_t GNUNET_strlcpy(char *dst, const char *src, size_t n)
Like strlcpy but portable.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Reply from ARM to client for the GNUNET_MESSAGE_TYPE_ARM_LIST request followed by count '\0' terminat...
uint64_t request_id
ID of a request that is being replied to.
Reply from ARM to client.
struct GNUNET_TIME_AbsoluteNBO last_started_at
Time when the service was first started, if applicable.
uint16_t binary_index
String pool index for the service's binary.
struct GNUNET_TIME_AbsoluteNBO restart_at
Time when the service will be restarted, if applicable to the current status.
uint32_t status
Status from the 'enum GNUNET_ARM_ServiceStatus'.
int16_t last_exit_status
Last process exit status.
uint16_t name_index
String pool index for the service's name.
Status update from ARM to client.
Handle used to access files (and pipes).
Handle used to manage a pipe.
Handle to a message queue.
Message handler for a specific message type.
The notification context is the key datastructure for a convenience API used for transmission of noti...
Entry in list of pending tasks.
Handle to a client that is connected to a service.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
uint64_t request_id
non-zero if this request has been sent to the service.
struct ServiceListeningInfo * listen_head
Linked list of listen sockets associated with this service.
struct ServiceListeningInfo * listen_tail
Linked list of listen sockets associated with this service.
char * binary
Name of the binary used.
int pipe_control
Should we use pipes to signal this process? (YES for Java binaries and if we are on Windoze).
char * config
Name of the configuration file used.
int last_exit_status
Last exit status of the process.
struct ServiceList * next
This is a doubly-linked list.
struct GNUNET_TIME_Absolute last_started_at
Absolute time at which the process was (re-)started last.
struct GNUNET_OS_Process * proc
Process structure pointer of the child.
struct GNUNET_SERVICE_Client * killing_client
Client to notify upon kill completion (waitpid), NULL if we should simply restart the process.
struct GNUNET_TIME_Relative backoff
Process exponential backoff time.
struct ServiceList * prev
This is a doubly-linked list.
char * name
Name of the service.
int force_start
Is this service to be started by default (or did a client tell us explicitly to start it)?...
struct GNUNET_TIME_Absolute killed_at
Time we asked the service to shut down (used to calculate time it took the service to terminate).
struct GNUNET_TIME_Absolute restart_at
Absolute time at which the process is scheduled to restart in case of death.
uint64_t killing_client_request_id
ID of the request that killed the service (for reporting back).
Record with information about a listen socket we have open.
struct ServiceListeningInfo * prev
This is a linked list.
struct ServiceListeningInfo * next
This is a linked list.
struct sockaddr * service_addr
Address this socket is listening on.
struct ServiceList * sl
Service this listen socket is for.
socklen_t service_addr_len
Number of bytes in service_addr.
struct GNUNET_SCHEDULER_Task * accept_task
Task doing the accepting.
struct GNUNET_NETWORK_Handle * listen_socket
Our listening socket.