2 * collectd - src/rrdc.c
3 * Copyright (C) 2008 Florian octo Forster
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Florian octo Forster <octo at verplant.org>
25 #define SOCK_TEMPLATE "/tmp/rrdc.sock.XXXXXX"
27 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
31 int rrdd_connect (const char *path)
33 struct sockaddr_un sa;
36 pthread_mutex_lock (&lock);
40 pthread_mutex_unlock (&lock);
44 sd = socket (PF_UNIX, SOCK_STREAM, /* protocol = */ 0);
48 pthread_mutex_unlock (&lock);
52 memset (&sa, 0, sizeof (sa));
53 sa.sun_family = AF_UNIX;
54 strncpy (sa.sun_path, path, sizeof (sa.sun_path) - 1);
56 status = connect (sd, (struct sockaddr *) &sa, sizeof (sa));
60 pthread_mutex_unlock (&lock);
64 sh = fdopen (sd, "w+");
70 pthread_mutex_unlock (&lock);
74 pthread_mutex_unlock (&lock);
77 } /* int rrdd_connect */
79 int rrdd_disconnect (void)
83 pthread_mutex_lock (&lock);
87 pthread_mutex_unlock (&lock);
98 pthread_mutex_unlock (&lock);
101 } /* int rrdd_disconnect */
103 int rrdd_update (const char *filename, int values_num,
104 const char * const *values)
106 pthread_mutex_lock (&lock);
110 pthread_mutex_unlock (&lock);
114 pthread_mutex_unlock (&lock);
117 } /* int rrd_update_daemon */
120 * vim: set sw=2 sts=2 ts=8 et fdm=marker :