Skip to content

Commit

Permalink
o General code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Miller committed Nov 21, 2023
1 parent dadd402 commit 75adfd6
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/PasteboardDevice.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static int clipboard_close(clip_fd *fd) {
return 0;
}

static intptr_t clipboard_open(int major, int minor, clip_fd *fd) {
static int clipboard_open(int major, int minor, clip_fd *fd) {
// Zero fd_priv data
memset(&fd_priv(fd), 0, sizeof(fd_priv(fd)));

Expand Down
4 changes: 2 additions & 2 deletions fs/dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ static inline dev_t_ dev_fake_from_real(dev_t dev) {
#define DEV_CHAR 1

struct dev_rtc {
intptr_t (*open)(int major, int minor, struct fd *fd);
int (*open)(int major, int minor, struct fd *fd);
int (*close)(int major, int minor, struct fd *fd);
ssize_t (*read)(void *buf, size_t count);
};

struct dev_ops {
intptr_t (*open)(int major, int minor, struct fd *fd);
int (*open)(int major, int minor, struct fd *fd);
struct fd_ops fd;
};

Expand Down
13 changes: 4 additions & 9 deletions fs/dyndev.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int dyn_dev_register(struct dev_ops *ops, int type, int major, int minor) {
return 0;
}

static intptr_t dyn_open(int type, int major, int minor, struct fd *fd) {
static int dyn_open(int type, int major, int minor, struct fd *fd) {
assert((type == DEV_CHAR) || (type == DEV_BLOCK));
assert(major == DYN_DEV_MAJOR || major == DEV_RTC_MAJOR); // mkemkemke
// it's safe to access devs without locking (read-only)
Expand All @@ -73,15 +73,10 @@ static intptr_t dyn_open(int type, int major, int minor, struct fd *fd) {
return 0;
}

static intptr_t dyn_open_char(int major, int minor, struct fd *fd) {
static int dyn_open_char(int major, int minor, struct fd *fd) {
return dyn_open(DEV_CHAR, major, minor, fd);
}

static intptr_t rtc_open(int major, int minor, struct fd *fd) {
//return &(intptr_t)(major, minor, fd);
return (intptr_t)fd;
}

struct rtc_time {
int tm_sec; /* seconds */
int tm_min; /* minutes */
Expand All @@ -91,7 +86,7 @@ struct rtc_time {
int tm_year; /* year */
};

intptr_t rtc_dev(void *buf, size_t count) {
int rtc_dev(void *buf, size_t count) {
if (count < sizeof(struct rtc_time)) {
errno = EFAULT;
return -1;
Expand Down Expand Up @@ -120,5 +115,5 @@ struct dev_ops dyn_dev_char = {
};

struct dev_ops rtc_dev_char = {
.open = rtc_dev,
.open = dyn_open_char,
};
13 changes: 9 additions & 4 deletions kernel/uname.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ char *uname_hostname_override = NULL;


void do_uname(struct uname *uts) {
if (uts == NULL) {
printk("ERROR: Null pointer provided to do_uname()\n");
return;
}

struct utsname real_uname;
if (uname(&real_uname) < 0) {
printk("ERROR: uname failed\n");
Expand Down Expand Up @@ -41,10 +46,10 @@ void do_uname(struct uname *uts) {
const char *uname_version = "iSH-AOK"; // Version should be defined or externally managed

// Fill the uname structure
strncpy(uts->arch, "i686", sizeof(uts->arch));
strncpy(uts->domain, "(none)", sizeof(uts->domain));
strncpy(uts->release, "4.20.69-ish_aok", sizeof(uts->release));
strncpy(uts->system, "Linux", sizeof(uts->system));
strlcpy(uts->arch, "i686", sizeof(uts->arch));
strlcpy(uts->domain, "(none)", sizeof(uts->domain));
strlcpy(uts->release, "4.20.69-ish_aok", sizeof(uts->release));
strlcpy(uts->system, "Linux", sizeof(uts->system));
snprintf(uts->hostname, sizeof(uts->hostname), "%s", hostname);
snprintf(uts->version, sizeof(uts->version), "%s %s", uname_version, build_date);
}
Expand Down
2 changes: 1 addition & 1 deletion util/sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int wait_for_ignore_signals(cond_t *cond, lock_t *lock, struct timespec *timeout
}
int rc = 0;
char saveme[16];
strncpy(saveme, lock->lname, 16); // Save for later
strlcpy(saveme, lock->lname, 16); // Save for later
#if LOCK_DEBUG
struct lock_debug lock_tmp = lock->debug;
lock->debug = (struct lock_debug) { .initialized = lock->debug.initialized };
Expand Down
13 changes: 6 additions & 7 deletions util/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ static inline void lock_init(lock_t *lock, char lname[16]) {
}

if(lname != NULL) {
strncpy(lock->lname, lname, 16);
strlcpy(lock->lname, lname, 16);
} else {
strncpy(lock->lname, "WTF", 16);
strlcpy(lock->lname, "WTF", 16);
}
lock->wait4 = false;
#if LOCK_DEBUG
Expand Down Expand Up @@ -97,8 +97,8 @@ static inline void atomic_l_lockf(char lname[16], const char *file, int line) {
}
}
if(!res) {
strncpy((char *)&atomic_l_lock.comm, current_comm(), 16);
strncpy((char *)&atomic_l_lock.lname, lname, 16);
strlcpy((char *)&atomic_l_lock.comm, current_comm(), 16);
strlcpy((char *)&atomic_l_lock.lname, lname, 16);
modify_locks_held_count_wrapper(1);
} else {
printk("Error on locking lock (%s) Called from %s:%d\n", lname, file, line);
Expand All @@ -114,7 +114,7 @@ static inline void atomic_l_unlockf(void) {
return;
int res = 0;
modify_critical_region_counter_wrapper(1, __FILE__, __LINE__);
strncpy((char *)&atomic_l_lock.lname,"\0", 1);
strlcpy((char *)&atomic_l_lock.lname,"\0", 1);
res = pthread_mutex_unlock(&atomic_l_lock.m);
if(res) {
printk("ERROR: unlocking locking lock\n");
Expand Down Expand Up @@ -164,8 +164,7 @@ static inline void complex_lockt(lock_t *lock, int log_lock, __attribute__((unus
lock->owner = pthread_self();
lock->pid = current_pid();
lock->uid = current_uid();
strncpy(lock->comm, current_comm(), sizeof(lock->comm) - 1);
lock->comm[sizeof(lock->comm) - 1] = '\0'; // Null-terminate just in case
strlcpy(lock->comm, current_comm(), sizeof(lock->comm) );
}

static inline void __lock(lock_t *lock, int log_lock, __attribute__((unused)) const char *file, __attribute__((unused)) int line) {
Expand Down

0 comments on commit 75adfd6

Please sign in to comment.