pid_t is signed, so usually it's been written to strings as signed long.
The actual pid values should never be negative, so practically it shouldn't
matter if it's written as signed or unsigned. However, due to bugs it's
theoretically possible that some garbage value gets written out.
kill() handles negative PIDs by killing entire process groups. By writing
pid_t as unsigned number we can prevent any (theoretical) issues where
kill() ends up killing entire process groups.
Change only some of the places to unsigned where the value might end up
used for kill(). Usually the signed writing is used only for log messages
where it might be more useful to see the negative numbers clearly
(especially -1 as unknown/unset might be used somewhere).
hash_table_iterate(iter, limit->session_hash,
&conn_guid, &session)) T_BEGIN {
str_truncate(str, 0);
- str_printfa(str, "%ld\t", (long)session->process->pid);
+ str_printfa(str, "%lu\t", (unsigned long)session->process->pid);
str_append_tabescaped(str, session->userip->username);
str_append_c(str, '\t');
str_append_tabescaped(str, session->service);
str_append_c(str, '(');
array_foreach_elem(&user->pids, pid)
- str_printfa(str, "%ld ", (long)pid);
+ str_printfa(str, "%lu ", (unsigned long)pid);
if (str_len(str) > 1)
str_truncate(str, str_len(str)-1);
str_append_c(str, ')');
const struct service_process *process)
{
str_append_tabescaped(str, process->service->set->name);
- str_printfa(str, "\t%ld\t%u\t%u\t%ld\t%ld\t%ld\n",
- (long)process->pid, process->available_count,
+ str_printfa(str, "\t%lu\t%u\t%u\t%ld\t%ld\t%ld\n",
+ (unsigned long)process->pid, process->available_count,
process->total_count, (long)process->idle_start,
(long)process->last_status_update,
(long)process->last_kill_sent);
} T_END;
str_append_c(cmd->str, '\t');
str_append_tabescaped(cmd->str, session->service);
- str_printfa(cmd->str, "\t%ld", (long)session->pid);
+ str_printfa(cmd->str, "\t%lu", (unsigned long)session->pid);
str_printfa(cmd->str, "\t%d", !session->disconnected);
client_export_timeval(cmd->str, &session->last_update);
str_printfa(cmd->str, "\t%u\t", session->num_cmds);