<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;" dir="ltr">
<p><span style="font-family:monospace">>2017-01-12 11:20 GMT+03:00 Dmitry Safonov <0x7f454c46@gmail.com>:
<br>
>> 2017-01-12 9:27 GMT+03:00 Vitaly Ostrosablin <vostrosablin@virtuozzo.com>: <br>
>>> cat *.pid works when we have only one running process at any moment. <br>
>>> That's because pidfiles contain no newlines and cat will just <br>
>>> concatenate content of all files present in directory. So, e.g., if we <br>
>>> have pidfiles: <br>
>>> <br>
>>> 31338 <br>
>>> 31359 <br>
>>> 31880 <br>
>>> 31884 <br>
>>> 31889 <br>
>>> <br>
>>> cat will build following string from those pidfiles: <br>
>>> <br>
>>> 3133831359318803188431889 <br>
>> <br>
>> I don't mind the patch, but your explanation looks obiviously wrong: <br>
>> [test]$ echo 123 > 1.txt <br>
>> [test]$ echo 456 > 2.txt <br>
>> [test]$ cat *.txt <br>
>> 123 <br>
>> 456 <br>
>> [test]$ cat Makefile <br>
>> all: <br>
>> cat *.txt <br>
>> [test]$ make <br>
>> cat *.txt <br>
>> 123 <br>
>> 456 <br>
> <br>
>[test]$ cat Makefile <br>
>all: <br>
> echo `cat *.txt` <br>
>[test]$ make <br>
>echo `cat *.txt` <br>
>123 456 <br>
>[test]$ <br>
> </span></p>
<p><span style="font-family:monospace"><br>
</span></p>
<p><font face="monospace">It doesn't look really wrong. What cat does is just a concatenation</font></p>
<p><font face="monospace">of files content and doesn't modify it in any way. What you put into</font></p>
<p><font face="monospace">files is what you get. So, concatenating '123\n' and '456\n' gives</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">123</font></p>
<p><font face="monospace">456</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">Now let's do same with concatenation of '123' and '456'. The result</font></p>
<p><font face="monospace">is clearly:</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">123456</font></p>
<p><font face="monospace"><br>
</font></p>
<p><font face="monospace">cat doesn't append it's own newlines. </font><span style="font-size: 12pt;">Now let's use echo with no-newline</span></p>
<p><span style="font-size: 12pt;">option:</span></p>
<p><span style="font-size: 12pt;"><br>
</span></p>
<p><span style="font-size: 12pt;"></p>
<div> echo -n 123 > 1.txt</div>
<div> echo -n 456 > 2.txt</div>
<div> cat *.txt</div>
<div>123456%</div>
<div><br>
</div>
<div>(Percent sign at end in zsh means that output ended without newline being</div>
<div>printed.)</div>
<div><br>
</div>
<div>Here's how we write the pidfile in zdtm lib/test.c:</div>
<div><br>
</div>
<div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>if (dprintf(fd, "%d", pid) == -1) {</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>fprintf(stderr, "Can't write in the file %s: %m\n", tmp);</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>goto err_c;</div>
<div><span class="Apple-tab-span" style="white-space:pre"></span>}</div>
</div>
<div><br>
</div>
<div>It just prints %d, i.e. pid only, without newline at end. So, if we were to cat</div>
<div>all pidfiles, we'll just <span style="font-size: 12pt;">get a single huge undelimited number.</span></div>
</span>
<p></p>
<p><span style="font-family:monospace"><br>
>> <br>
>> Is it something that depends on environment, like ${IFS} in bash? <br>
>> Check, please. <br>
>> <br>
>>> <br>
>>> Obviously, kill would fail to send signals to processes, because it's <br>
>>> now a single big number, which cannot be unambigously split back in <br>
>>> general case. <br>
>>> <br>
>>> That's where awk comes in. We don't need to modify C part of tests to <br>
>>> print newlines at end of file. We just order awk to print content of <br>
>>> each file, which adds a newline at end - problem solved, kill can once <br>
>>> again parse, which PIDs it get and send proper signals to them. Also, <br>
>>> should be completely safe for zdtm.py, because it doesn't use Makefiles <br>
>>> and sends signals on it's own. <br>
>>> --- <br>
>>> test/zdtm/static/Makefile | 4 ++-- <br>
>>> test/zdtm/transition/Makefile | 4 ++-- <br>
>>> 2 files changed, 4 insertions(+), 4 deletions(-) <br>
>>> <br>
>>> diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile <br>
>>> index af1254f5..8fe9d953 100644 <br>
>>> --- a/test/zdtm/static/Makefile <br>
>>> +++ b/test/zdtm/static/Makefile <br>
>>> @@ -338,7 +338,7 @@ start: $(PID) $(STATE) <br>
>>> check_start: $(PID:%.pid=%.is_running) <br>
>>> <br>
>>> stop: $(STATE_OUT) <br>
>>> - -kill -TERM `cat *.pid` <br>
>>> + -kill -TERM `awk '{print}' *.pid` <br>
>>> <br>
>>> WAIT_TIME=240 <br>
>>> %.stop: %.pid % <br>
>>> @@ -356,7 +356,7 @@ WAIT_TIME=240 <br>
>>> wait_stop: <br>
>>> i=0; >> while [ $$i -lt $(WAIT_TIME) ] ; do >> - kill -0 `cat *.pid 2>/dev/null` 2><br>
/dev/null || break; >> + kill -0 `awk '{print}' *.pid 2>/dev/null` 2>/dev/null || break; >> sleep 1; >><br>
i=`expr $$i + 1`; >> done <br>
>>> diff --git a/test/zdtm/transition/Makefile b/test/zdtm/transition/Makefile <br>
>>> index 7ddb2384..dfc10ef5 100644 <br>
>>> --- a/test/zdtm/transition/Makefile <br>
>>> +++ b/test/zdtm/transition/Makefile <br>
>>> @@ -65,12 +65,12 @@ start: $(PID) <br>
>>> check_start: $(PID:%.pid=%.is_running) <br>
>>> <br>
>>> stop: <br>
>>> - -kill -TERM `cat *.pid` <br>
>>> + -kill -TERM `awk '{print}' *.pid` <br>
>>> <br>
>>> WAIT_TIME=10 <br>
>>> wait_stop: <br>
>>> -for i in `seq 1 $(WAIT_TIME)`; do >> - kill -0 `cat *.pid 2>/dev/null` 2>/dev/null || break; >> + <br>
kill -0 `awk '{print}' *.pid 2>/dev/null` 2>/dev/null || break; >> sleep 1; >> done
<br>
>>> <br>
>>> -- <br>
>>> 2.11.0 <br>
>>> <br>
>>> _______________________________________________ <br>
>>> CRIU mailing list <br>
>>> CRIU@openvz.org <br>
>>> https://lists.openvz.org/mailman/listinfo/criu <br>
> <br>
>> <br>
>> <br>
>> <br>
>> -- <br>
>> Dmitry <br>
> <br>
> <br>
> <br>
>-- <br>
> Dmitry<br>
<br>
</span><br>
</p>
<div style="color: rgb(0, 0, 0);"></div>
</div>
</body>
</html>