Skip to content

Commit

Permalink
Replace fscanf() with fgets() when reading hostapd PID file
Browse files Browse the repository at this point in the history
This works around some strange hwsim testing issues with UML where the
fscanf() call seemed to hang in signal handler whereas fgets() had no
issues reading the PID string.

Signed-off-by: Jouni Malinen <quic_jouni@quicinc.com>
  • Loading branch information
Jouni Malinen committed Dec 22, 2024
1 parent 6e191ad commit 2279b56
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ap.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,19 @@ static enum sigma_cmd_result cmd_ap_ca_version(struct sigma_dut *dut,
void kill_hostapd_process_pid(struct sigma_dut *dut)
{
FILE *f;
int pid, res;
int pid;
char *res;
char path[100];
int count;

f = fopen(SIGMA_DUT_HOSTAPD_PID_FILE, "r");
if (!f)
return;
res = fscanf(f, "%d", &pid);
res = fgets(path, sizeof(path), f);
fclose(f);
if (res != 1)
if (!res)
return;
pid = atoi(res);
sigma_dut_print(dut, DUT_MSG_INFO, "Killing hostapd pid %d", pid);
kill(pid, SIGTERM);
snprintf(path, sizeof(path), "/proc/%d", pid);
Expand Down

0 comments on commit 2279b56

Please sign in to comment.