ia64/xen-unstable

view tools/xenstore/xs_lib.h @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents ef9591d03fdd
children 93e27f7ca8a8 61b3b357d827 62d815160f01
line source
1 /*
2 Common routines between Xen store user library and daemon.
3 Copyright (C) 2005 Rusty Russell IBM Corporation
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
20 #ifndef _XS_LIB_H
21 #define _XS_LIB_H
23 #include <stdbool.h>
24 #include <limits.h>
25 #include <xenctrl.h>
27 /* Bitmask of permissions. */
28 enum xs_perm_type {
29 XS_PERM_NONE = 0,
30 XS_PERM_READ = 1,
31 XS_PERM_WRITE = 2,
32 /* Internal use. */
33 XS_PERM_ENOENT_OK = 4,
34 XS_PERM_OWNER = 8,
35 };
37 struct xs_permissions
38 {
39 unsigned int id;
40 enum xs_perm_type perms;
41 };
43 /* Each 10 bits takes ~ 3 digits, plus one, plus one for nul terminator. */
44 #define MAX_STRLEN(x) ((sizeof(x) * CHAR_BIT + CHAR_BIT-1) / 10 * 3 + 2)
46 /* Path for various daemon things: env vars can override. */
47 const char *xs_daemon_socket(void);
48 const char *xs_daemon_socket_ro(void);
49 const char *xs_domain_dev(void);
50 const char *xs_daemon_tdb(void);
52 /* Simple write function: loops for you. */
53 bool xs_write_all(int fd, const void *data, unsigned int len);
55 /* Convert strings to permissions. False if a problem. */
56 bool xs_strings_to_perms(struct xs_permissions *perms, unsigned int num,
57 const char *strings);
59 /* Convert permissions to a string (up to len MAX_STRLEN(domid_t)+1). */
60 bool xs_perm_to_string(const struct xs_permissions *perm, char *buffer);
62 /* Given a string and a length, count how many strings (nul terms). */
63 unsigned int xs_count_strings(const char *strings, unsigned int len);
65 #endif /* _XS_LIB_H */