core icon indicating copy to clipboard operation
core copied to clipboard

Fixes: CFE-3982 do not kill unrelated process

Open peckpeck opened this issue 2 years ago • 3 comments

Pull request to fix https://tracker.mender.io/browse/CFE-3982

peckpeck avatar May 24 '22 10:05 peckpeck

About the coding style, is there anything else than the function name that you want to point me to ?

peckpeck avatar May 30 '22 14:05 peckpeck

About the coding style, is there anything else than the function name that you want to point me to ?

@peckpeck Some things I see at first glance:

  1. Space after if, commas, and around operators (like >).
  2. Opening curly brace on separate line ({).
  3. Don't do if's without curly braces.
  4. Avoid unnecessary typecasts.
  5. Pointer asterisk to the right, next to the name (FILE *f).
  6. Compare pointers to NULL explicitly (if (f != NULL)).

olehermanse avatar May 31 '22 12:05 olehermanse

sorry for the delay

peckpeck avatar Sep 15 '22 12:09 peckpeck

@vpodzime any news on this ?

peckpeck avatar Dec 14 '22 08:12 peckpeck

Hi @peckpeck ! as far as i know, Windows is not the only platform without the /proc file. Please correct me if I'm wrong. In libpromises/process_select.h we have some functions for querying processes. Maybe you can use those? E.g.

ClearProcessTable(); /* Make sure old process table is not cached */

Item *procs = NULL;
if (LoadProcessTable())
{
    ProcessSelect ps = PROCESS_SELECT_INIT;
    ps.max_pid = ps.min_pid = lock_data.pid;
    procs = SelectProcesses("cf-.*", &ps, true);
}
if (procs == NULL)
{
    /* Process select returned nothing, it must be an unrelated process */
    return false;
}
DeleteItemList(procs);
return true;

Not sure if this would work, but feel free to give it a try. Otherwise you could maybe guard it with the #ifdef __linux__ macro.

larsewi avatar Dec 14 '22 15:12 larsewi

PR updated, sorry for the delay

peckpeck avatar Aug 30 '23 07:08 peckpeck

@peckpeck I took your code as a base for my work on the related ticket. Thank you for your contribution!

vpodzime avatar Nov 07 '23 10:11 vpodzime