-
-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sysdeps/ironclad: Miscellaneous sysdeps updates
- Loading branch information
Showing
8 changed files
with
404 additions
and
133 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include <bits/ensure.h> | ||
#include <stddef.h> | ||
#include <errno.h> | ||
#include <utmpx.h> | ||
#include <stdio.h> | ||
#include <time.h> | ||
#include <paths.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
|
||
int utmpx_file = -1; | ||
|
||
void updwtmpx(const char *, const struct utmpx *) { | ||
// Empty as musl does | ||
} | ||
|
||
void endutxent(void) { | ||
if (utmpx_file >= 0) { | ||
close(utmpx_file); | ||
} | ||
} | ||
|
||
void setutxent(void) { | ||
if (utmpx_file < 0) { | ||
utmpx_file = open(UTMPX_FILE, O_RDWR | O_CREAT, 0755); | ||
} else { | ||
lseek(utmpx_file, 0, SEEK_SET); | ||
} | ||
} | ||
|
||
struct utmpx returned; | ||
|
||
struct utmpx *getutxent(void) { | ||
if (utmpx_file < 0) { | ||
setutxent(); | ||
if (utmpx_file < 0) { | ||
return NULL; | ||
} | ||
} | ||
|
||
if (read(utmpx_file, &returned, sizeof(struct utmpx)) != sizeof(struct utmpx)) { | ||
return NULL; | ||
} | ||
|
||
return &returned; | ||
} | ||
|
||
struct utmpx *pututxline(const struct utmpx *added) { | ||
if (utmpx_file < 0) { | ||
setutxent(); | ||
if (utmpx_file < 0) { | ||
return NULL; | ||
} | ||
} | ||
|
||
lseek(utmpx_file, 0, SEEK_END); | ||
if (write(utmpx_file, added, sizeof(struct utmpx)) != sizeof(struct utmpx)) { | ||
return NULL; | ||
} | ||
|
||
return (struct utmpx *)added; | ||
} | ||
|
||
int utmpxname(const char *path) { | ||
if (utmpx_file > 0) { | ||
close(utmpx_file); | ||
} | ||
|
||
utmpx_file = open(path, O_RDWR | O_CREAT, 0755); | ||
if (utmpx_file > 0) { | ||
lseek(utmpx_file, 0, SEEK_END); | ||
return 1; | ||
} else { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
|
||
#ifndef _UTMPX_H | ||
#define _UTMPX_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <abi-bits/pid_t.h> | ||
#include <bits/posix/timeval.h> | ||
|
||
#define UTMPX_FILE "/var/run/utmp" | ||
#define WTMPX_FILE "/var/run/wtmp" | ||
|
||
// Struct definition taken from musl | ||
struct utmpx { | ||
short ut_type; | ||
short __ut_pad1; | ||
pid_t ut_pid; | ||
char ut_line[32]; | ||
char ut_id[4]; | ||
char ut_user[32]; | ||
char ut_host[256]; | ||
struct { | ||
short __e_termination; | ||
short __e_exit; | ||
} ut_exit; | ||
int ut_session, __ut_pad2; | ||
struct timeval ut_tv; | ||
unsigned ut_addr_v6[4]; | ||
char __unused[20]; | ||
}; | ||
|
||
#ifndef __MLIBC_ABI_ONLY | ||
|
||
void updwtmpx(const char *, const struct utmpx *); | ||
int utmpxname(const char *); | ||
struct utmpx *pututxline(const struct utmpx *); | ||
struct utmpx *getutxent(void); | ||
void setutxent(void); | ||
void endutxent(void); | ||
|
||
#endif /* !__MLIBC_ABI_ONLY */ | ||
|
||
#define EMPTY 0 | ||
#define RUN_LVL 1 | ||
#define BOOT_TIME 2 | ||
#define NEW_TIME 3 | ||
#define OLD_TIME 4 | ||
#define INIT_PROCESS 5 | ||
#define LOGIN_PROCESS 6 | ||
#define USER_PROCESS 7 | ||
#define DEAD_PROCESS 8 | ||
|
||
#define __UT_HOSTSIZE 256 | ||
#define __UT_NAMESIZE 32 | ||
#define __UT_LINESIZE 32 | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // _UTMPX_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters