cflags-v13.c (3475B)
1 // $Id$ --*- c -*-- 2 3 // Copyright (C) 2004 Enrico Scholz <ensc@delenn.intern.sigma-chemnitz.de> 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; version 2 of the License. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with this program; if not, write to the Free Software 16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 18 19 #ifdef HAVE_CONFIG_H 20 # include <config.h> 21 #endif 22 23 #include "vserver.h" 24 #include "internal.h" 25 #include <lib_internal/util-dimof.h> 26 27 #include <string.h> 28 #include <strings.h> 29 #include <assert.h> 30 31 #define DECL(STR, VAL) { STR, sizeof(STR)-1, VAL } 32 33 static struct Mapping_uint64 const VALUES[] = { 34 DECL("lock", VC_VXF_INFO_LOCK), 35 DECL("nproc", VC_VXF_INFO_NPROC), 36 DECL("private", VC_VXF_INFO_PRIVATE), 37 DECL("fakeinit", VC_VXF_INFO_INIT), 38 39 DECL("hideinfo", VC_VXF_INFO_HIDEINFO), 40 DECL("ulimit", VC_VXF_INFO_ULIMIT), 41 DECL("namespace", VC_VXF_INFO_NAMESPACE), 42 43 DECL("sched_hard", VC_VXF_SCHED_HARD), 44 DECL("sched_prio", VC_VXF_SCHED_PRIO), 45 DECL("sched_pause", VC_VXF_SCHED_PAUSE), 46 47 DECL("virt_mem", VC_VXF_VIRT_MEM), 48 DECL("virt_uptime", VC_VXF_VIRT_UPTIME), 49 DECL("virt_cpu", VC_VXF_VIRT_CPU), 50 DECL("virt_load", VC_VXF_VIRT_LOAD), 51 DECL("virt_time", VC_VXF_VIRT_TIME), 52 53 DECL("hide_mount", VC_VXF_HIDE_MOUNT), 54 DECL("hide_netif", VC_VXF_HIDE_NETIF), 55 DECL("hide_vinfo", VC_VXF_HIDE_VINFO), 56 57 DECL("state_setup", VC_VXF_STATE_SETUP), 58 DECL("state_init", VC_VXF_STATE_INIT), 59 DECL("state_admin", VC_VXF_STATE_ADMIN), 60 61 DECL("sc_helper", VC_VXF_SC_HELPER), 62 DECL("persistent", VC_VXF_PERSISTENT), 63 DECL("reboot_kill", VC_VXF_REBOOT_KILL), 64 65 DECL("fork_rss", VC_VXF_FORK_RSS), 66 DECL("prolific", VC_VXF_PROLIFIC), 67 DECL("igneg_nice", VC_VXF_IGNEG_NICE), 68 DECL("igneg_ionice", VC_VXF_IGNEG_IONICE), 69 70 // Some pseudo flags 71 DECL("secure", VC_VXF_HIDE_NETIF), 72 DECL("default", VC_VXF_VIRT_UPTIME|VC_VXF_SC_HELPER), 73 74 // Aliases for the legacy flags 75 DECL("info_lock", VC_VXF_INFO_LOCK), 76 DECL("info_nproc", VC_VXF_INFO_NPROC), 77 DECL("info_private", VC_VXF_INFO_PRIVATE), 78 DECL("info_init", VC_VXF_INFO_INIT), 79 80 DECL("info_hideinfo", VC_VXF_INFO_HIDEINFO), 81 DECL("info_ulimit", VC_VXF_INFO_ULIMIT), 82 DECL("info_namespace", VC_VXF_INFO_NAMESPACE), 83 // 2.6 name 84 DECL("info_nspace", VC_VXF_INFO_NAMESPACE), 85 }; 86 87 inline static char const * 88 removePrefix(char const *str, size_t *len) 89 { 90 if ((len==0 || *len==0 || *len>4) && 91 strncasecmp("vxf_", str, 4)==0) { 92 if (len && *len>4) *len -= 4; 93 return str+4; 94 } 95 else 96 return str; 97 } 98 99 uint_least64_t 100 vc_text2cflag(char const *str, size_t len) 101 { 102 char const * tmp = removePrefix(str, &len); 103 ssize_t idx = utilvserver_value2text_uint64(tmp, len, 104 VALUES, DIM_OF(VALUES)); 105 if (idx==-1) return 0; 106 else return VALUES[idx].val; 107 } 108 109 char const * 110 vc_locflag2text(uint_least64_t *val) 111 { 112 ssize_t idx = utilvserver_text2value_uint64(val, 113 VALUES, DIM_OF(VALUES)); 114 115 if (idx==-1) return 0; 116 else return VALUES[idx].id; 117 }