utxdb.c (202188) | utxdb.c (202530) |
---|---|
1/*- 2 * Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/lib/libc/gen/utxdb.c 202188 2010-01-13 17:29:55Z ed $"); | 28__FBSDID("$FreeBSD: head/lib/libc/gen/utxdb.c 202530 2010-01-17 21:40:05Z ed $"); |
29 30#include "namespace.h" 31#include <sys/endian.h> 32#include <sys/param.h> | 29 30#include "namespace.h" 31#include <sys/endian.h> 32#include <sys/param.h> |
33#include <stdlib.h> |
|
33#include <string.h> 34#include <utmpx.h> 35#include "utxdb.h" 36#include "un-namespace.h" 37 38#define UTOF_STRING(ut, fu, field) do { \ 39 strncpy((fu)->fu_ ## field, (ut)->ut_ ## field, \ 40 MIN(sizeof (fu)->fu_ ## field, sizeof (ut)->ut_ ## field)); \ --- 36 unchanged lines hidden (view full) --- 77 break; 78 case INIT_PROCESS: 79 UTOF_ID(ut, fu); 80 UTOF_PID(ut, fu); 81 break; 82 case LOGIN_PROCESS: 83 UTOF_ID(ut, fu); 84 UTOF_STRING(ut, fu, user); | 34#include <string.h> 35#include <utmpx.h> 36#include "utxdb.h" 37#include "un-namespace.h" 38 39#define UTOF_STRING(ut, fu, field) do { \ 40 strncpy((fu)->fu_ ## field, (ut)->ut_ ## field, \ 41 MIN(sizeof (fu)->fu_ ## field, sizeof (ut)->ut_ ## field)); \ --- 36 unchanged lines hidden (view full) --- 78 break; 79 case INIT_PROCESS: 80 UTOF_ID(ut, fu); 81 UTOF_PID(ut, fu); 82 break; 83 case LOGIN_PROCESS: 84 UTOF_ID(ut, fu); 85 UTOF_STRING(ut, fu, user); |
86 /* XXX: bug in the specification? Needed for getutxline(). */ 87 UTOF_STRING(ut, fu, line); |
|
85 UTOF_PID(ut, fu); 86 break; 87 case DEAD_PROCESS: 88 UTOF_ID(ut, fu); 89 UTOF_PID(ut, fu); 90 break; 91 default: 92 fu->fu_type = EMPTY; --- 20 unchanged lines hidden (view full) --- 113} while (0) 114#define FTOU_TV(fu, ut) do { \ 115 uint64_t t; \ 116 t = be64toh((fu)->fu_tv); \ 117 (ut)->ut_tv.tv_sec = t / 1000000; \ 118 (ut)->ut_tv.tv_usec = t % 1000000; \ 119} while (0) 120 | 88 UTOF_PID(ut, fu); 89 break; 90 case DEAD_PROCESS: 91 UTOF_ID(ut, fu); 92 UTOF_PID(ut, fu); 93 break; 94 default: 95 fu->fu_type = EMPTY; --- 20 unchanged lines hidden (view full) --- 116} while (0) 117#define FTOU_TV(fu, ut) do { \ 118 uint64_t t; \ 119 t = be64toh((fu)->fu_tv); \ 120 (ut)->ut_tv.tv_sec = t / 1000000; \ 121 (ut)->ut_tv.tv_usec = t % 1000000; \ 122} while (0) 123 |
121void 122futx_to_utx(const struct futx *fu, struct utmpx *ut) | 124struct utmpx * 125futx_to_utx(const struct futx *fu) |
123{ | 126{ |
127 static struct utmpx *ut; |
|
124 | 128 |
125 memset(ut, 0, sizeof *ut); | 129 if (ut == NULL) { 130 ut = calloc(1, sizeof *ut); 131 if (ut == NULL) 132 return (NULL); 133 } else { 134 memset(ut, 0, sizeof *ut); 135 } |
126 127 switch (fu->fu_type) { 128 case BOOT_TIME: 129 case OLD_TIME: 130 case NEW_TIME: 131 /* Extension: shutdown time. */ 132 case SHUTDOWN_TIME: 133 break; --- 7 unchanged lines hidden (view full) --- 141 break; 142 case INIT_PROCESS: 143 FTOU_ID(fu, ut); 144 FTOU_PID(fu, ut); 145 break; 146 case LOGIN_PROCESS: 147 FTOU_ID(fu, ut); 148 FTOU_STRING(fu, ut, user); | 136 137 switch (fu->fu_type) { 138 case BOOT_TIME: 139 case OLD_TIME: 140 case NEW_TIME: 141 /* Extension: shutdown time. */ 142 case SHUTDOWN_TIME: 143 break; --- 7 unchanged lines hidden (view full) --- 151 break; 152 case INIT_PROCESS: 153 FTOU_ID(fu, ut); 154 FTOU_PID(fu, ut); 155 break; 156 case LOGIN_PROCESS: 157 FTOU_ID(fu, ut); 158 FTOU_STRING(fu, ut, user); |
159 /* XXX: bug in the specification? Needed for getutxline(). */ 160 FTOU_STRING(fu, ut, line); |
|
149 FTOU_PID(fu, ut); 150 break; 151 case DEAD_PROCESS: 152 FTOU_ID(fu, ut); 153 FTOU_PID(fu, ut); 154 break; 155 default: 156 ut->ut_type = EMPTY; | 161 FTOU_PID(fu, ut); 162 break; 163 case DEAD_PROCESS: 164 FTOU_ID(fu, ut); 165 FTOU_PID(fu, ut); 166 break; 167 default: 168 ut->ut_type = EMPTY; |
157 return; | 169 return (ut); |
158 } 159 160 FTOU_TYPE(fu, ut); 161 FTOU_TV(fu, ut); | 170 } 171 172 FTOU_TYPE(fu, ut); 173 FTOU_TV(fu, ut); |
174 return (ut); |
|
162} | 175} |