Refactor to remove no-op calls

This removes the call-sites of the removed setuid feature
This commit is contained in:
Benny Baumann 2021-02-16 19:44:59 +01:00
parent a73064dda9
commit 82157f598e
5 changed files with 6 additions and 27 deletions

3
CRT.h
View File

@ -160,9 +160,6 @@ extern int CRT_scrollWheelVAmount;
extern ColorScheme CRT_colorScheme; extern ColorScheme CRT_colorScheme;
static inline void CRT_dropPrivileges(void) { }
static inline void CRT_restorePrivileges(void) { }
void CRT_init(const Settings* settings, bool allowUnicode); void CRT_init(const Settings* settings, bool allowUnicode);
void CRT_done(void); void CRT_done(void);

View File

@ -34,9 +34,7 @@ static void EnvScreen_scan(InfoScreen* this) {
Panel_prune(panel); Panel_prune(panel);
CRT_dropPrivileges();
char* env = Platform_getProcessEnv(this->process->pid); char* env = Platform_getProcessEnv(this->process->pid);
CRT_restorePrivileges();
if (env) { if (env) {
for (const char* p = env; *p; p = strrchr(p, 0) + 1) for (const char* p = env; *p; p = strrchr(p, 0) + 1)
InfoScreen_addLine(this, p); InfoScreen_addLine(this, p);

View File

@ -479,10 +479,9 @@ bool Process_isTomb(const Process* this) {
} }
bool Process_setPriority(Process* this, int priority) { bool Process_setPriority(Process* this, int priority) {
CRT_dropPrivileges();
int old_prio = getpriority(PRIO_PROCESS, this->pid); int old_prio = getpriority(PRIO_PROCESS, this->pid);
int err = setpriority(PRIO_PROCESS, this->pid, priority); int err = setpriority(PRIO_PROCESS, this->pid, priority);
CRT_restorePrivileges();
if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) { if (err == 0 && old_prio != getpriority(PRIO_PROCESS, this->pid)) {
this->nice = priority; this->nice = priority;
} }
@ -494,10 +493,7 @@ bool Process_changePriorityBy(Process* this, Arg delta) {
} }
bool Process_sendSignal(Process* this, Arg sgn) { bool Process_sendSignal(Process* this, Arg sgn) {
CRT_dropPrivileges(); return kill(this->pid, sgn.i) == 0;
bool ok = (kill(this->pid, sgn.i) == 0);
CRT_restorePrivileges();
return ok;
} }
int Process_pidCompare(const void* v1, const void* v2) { int Process_pidCompare(const void* v1, const void* v2) {

View File

@ -125,10 +125,7 @@ static void readFields(ProcessField* fields, uint32_t* flags, const char* line)
} }
static bool Settings_read(Settings* this, const char* fileName, int initialCpuCount) { static bool Settings_read(Settings* this, const char* fileName, int initialCpuCount) {
FILE* fd; FILE* fd = fopen(fileName, "r");
CRT_dropPrivileges();
fd = fopen(fileName, "r");
CRT_restorePrivileges();
if (!fd) if (!fd)
return false; return false;
@ -284,15 +281,10 @@ static void writeMeterModes(Settings* this, FILE* fd, int column) {
} }
bool Settings_write(Settings* this) { bool Settings_write(Settings* this) {
FILE* fd; FILE* fd = fopen(this->filename, "w");
if (fd == NULL)
CRT_dropPrivileges();
fd = fopen(this->filename, "w");
CRT_restorePrivileges();
if (fd == NULL) {
return false; return false;
}
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n"); fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n"); fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n");
writeFields(fd, this->fields, "fields"); writeFields(fd, this->fields, "fields");
@ -410,7 +402,6 @@ Settings* Settings_new(int initialCpuCount) {
htopDir = String_cat(home, "/.config/htop"); htopDir = String_cat(home, "/.config/htop");
} }
legacyDotfile = String_cat(home, "/.htoprc"); legacyDotfile = String_cat(home, "/.htoprc");
CRT_dropPrivileges();
(void) mkdir(configDir, 0700); (void) mkdir(configDir, 0700);
(void) mkdir(htopDir, 0700); (void) mkdir(htopDir, 0700);
free(htopDir); free(htopDir);
@ -421,7 +412,6 @@ Settings* Settings_new(int initialCpuCount) {
free(legacyDotfile); free(legacyDotfile);
legacyDotfile = NULL; legacyDotfile = NULL;
} }
CRT_restorePrivileges();
} }
this->colorScheme = 0; this->colorScheme = 0;
this->enableMouse = true; this->enableMouse = true;

View File

@ -87,8 +87,6 @@ bool TraceScreen_forkTracer(TraceScreen* this) {
dup2(fdpair[1], STDERR_FILENO); dup2(fdpair[1], STDERR_FILENO);
close(fdpair[1]); close(fdpair[1]);
CRT_dropPrivileges();
char buffer[32] = {0}; char buffer[32] = {0};
xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid); xSnprintf(buffer, sizeof(buffer), "%d", this->super.process->pid);
execlp("strace", "strace", "-T", "-tt", "-s", "512", "-p", buffer, NULL); execlp("strace", "strace", "-T", "-tt", "-s", "512", "-p", buffer, NULL);