« first day (4030 days earlier)      last day (212 days later) » 

7:23 AM
@fra-san Correct. I was distinguishing between two cases.
a) exec is not able to launch the command because the command is not well formed, or for some other reason (syntax error).
b) exec launches the command, but the command exits with an error.
So, my understanding is that in case (a) exec returns. In case (b) it doesn't.
 
@FaheemMitha that’s correct.
 
@StephenKitt Thank you for the confirmation.
 
If you’re trying to understand exit codes from children to parents, you could avoid the whole exec...() thing and just use exit() in the child branch.
 
Can someone tell me what happens if one uses 'NULL' instead of NULL or (char *)0 in that last exec argument? My guess is that is a signpost for exec to stop collecting arguments. And if it doesn't see it, it continues collecting arguments? Till when?
 
@FaheemMitha it continues until it finds a 0 on the stack
 
7:28 AM
@StephenKitt Well, my use case involves exec. Specifically launching a command from the shell. That's why I'm including it.
@StephenKitt Null pointer?
 
> The list of arguments must be
terminated by a null pointer, and, since these are variadic
functions, this pointer must be cast (char *) NULL.
As explained in the manual. The NULL constant is a null pointer.
 
@StephenKitt OK. Is this a quote from the man page?
 
I guess C has no idea it is collecting garbage.
Not a lot of safety built in.
@StephenKitt Right, the exec man page.
Thank you.
So there is no requirement the arguments be separated in any way, for example.
 
@FaheemMitha no, there isn’t, since the argument separation is done by constructing the arguments to exec(). You might feel more comfortable using system() instead — that delegates everything to the shell, so you get redirection etc. as well.
 
7:33 AM
@StephenKitt Um, yes. But I thought that maybe those "real" arguments would satisfy some criterion that garbage would not. Like laid out in a certain way.
I don't have a problem with how exec works. Just trying to understand what it does.
And I realise that C by its nature doesn't have a lot of safety built in, and that's OK too.
 
@FaheemMitha they’re not laid out, the arguments themselves are all pointers — execlp() just sees a succession of pointers on the stack (or whatever the ABI uses to pass pointer arguments), and processes them until it finds a null pointer.
 
@StephenKitt Oh, right, they're pointers. And garbage could be pointers too?
 
@FaheemMitha a pointer is just a number. Whether it can be dereferenced is another matter ;-)
 
I don't even know whether pointers/addresses have a structure requirement. I guess that would depend on the machine.
@StephenKitt OK. Though my code didn't segfault at any point, which is what would expect to happen in that case.
 
@FaheemMitha given what your code is doing, you’re likely to quickly run into zeroes on the stack anyway
 
7:50 AM
The reason you have to cast is that the default interpretation of 0 is an int, which may not be the same size as a pointer. Due to how C variadic functions work the compiler doesn't know it's meant to be a pointer and can't widen itself. Inside the function, when it looks for a pointer on the stack, it gets mixed garbage instead of something it recognises as null (there are also other reasons, but this one is easy to imagine - 64-bit pointers, 32-bit ints gives half a zero and half detritus)
In reality, 0-without-cast will often work and you don't notice until your code fails on another machine
 
8:23 AM
@FaheemMitha you only segfault if you try to access (maybe even just try to write) memory not belonging to your process. With larger programs it's easy to get (un)lucky and silently corrupt your own memory. As far as I understand.
 
I have an enough old remote server that lacks many updates for various important programs such gcc and glibc, rubby ,.. etc how can I create an env that enables to get recent updates without root rights?
Or it's impossible one should look into another radical solution?
 
8:52 AM
"Enough old", we have that too in my native language
 
While we are on the subject, what does the compiler understand by NULL? Does it interpret that as a null pointer, or is that implementation dependent?
@EnthusiastiC Do you have root on that server? I'm assuming not.
@MichaelHomer I see. Thank you for the explanation.
@AndrasDeak I'm not sure how "memory belonging to your process" is determined.
 
@FaheemMitha it’s defined as ((void *)0)
 
In practice, as you say, it's possible to do quite a lot of reading, and never have a segfault. Though valgrind and friends will tell you about it if you ask.
@StephenKitt OK. So a null pointer, then.
 
@FaheemMitha strictly speaking it’s implementation-defined
But yes, it’s a pointer.
 
9:11 AM
@StephenKitt As normal with those things, I don't understand what that page is saying. So it sounds like it is safer to go with (char *)0, though it practice NULL will likely be understood to be a null pointer.
 
@FaheemMitha no, it’s safer to go with what the exec manpage says, (char *) NULL.
 
@StephenKitt Oh?
Oh, I've not seen that option actually used anywhere.
(char *)0 seems popular.
 
In example code I've looked at, I mean.
 
Yes, that’s what I gathered ;-).
 
9:14 AM
Also, (void *)NULL.
 
@FaheemMitha determined by whom?
 
@AndrasDeak I dunno. The kernel?
Isn't it the police in these cases?
 
Probably. So how would it not know what is owned memory?
 
@FaheemMitha yup. The important part being that it is a pointer, regardless of the expansion of NULL, for the reasons Michael gave above.
@FaheemMitha the police is the MMU; the kernel is the judiciary branch.
 
All of NULL, (char *)0, and (char *)NULL seem to be used. And one use of (void *)NULL in gnupg.
@StephenKitt I stand corrected.
@StephenKitt Yes, I understood that it's a pointer.
 
9:20 AM
@FaheemMitha if you want all the gory details (including platforms where the null pointer isn’t 0), see the C FAQs on the topic.
 
@AndrasDeak How would the process not know? No idea what the process knows or doesn't know.
As you probably have gathered, my knowledge of such things is close to NULL.
Anyway, I guess I'll stick with (char *)NULL, since apparently that's the safest.
 
@FaheemMitha the process needs to remember what memory it has allocated
but the stack is somewhat special
@FaheemMitha it’s the clearest IMO — the language guarantees that 0 cast to a pointer is also correct, regardless of the underlying representation. In my mind safety includes both the compiler’s interpretation and humans’ interpretation(s).
 
I once purchased the "Harbison and Steele" C reference manual, but have rarely looked at it. Maybe once in a while. It's still somewhere in my bookcases.
@StephenKitt OK.
 
9:37 AM
@StephenKitt I didn't realise the memory was managed by hardware. I thought the kernel (i.e. software) kept tabs. How does the hardware know about processes, anyway?
That was rhetorical. I'm sure the answer is complicated.
 
@FaheemMitha that’s the distinction in my comment above. The kernel keeps tabs, and knows about all the rules, which is why it’s the judiciary; it configures the MMU to apply the relevant limits, which is why the MMU is the police. When a process accesses memory it shouldn’t, the MMU reacts to the violation and asks the kernel what to do.
 
@StephenKitt Ah, I see. Thank you for the clarification.
Sounds like the CPU has a mini OS of its own.
 
Ben
Greetings.
:59412274 I was wondering what are common reasons that causing hard drive failure?
 
@FaheemMitha No, I don't
 
@EnthusiastiC Oh, then anything you do would have to be in your home directory, I suppose.
 
9:45 AM
indeed. I surrender.
 
I think you could create a small chroot in your home directory, if that would be helpful.
@EnthusiastiC You surrender?
 
Ben
I thought improper shutdown could damage files, and maybe more checking and repairing on restarting could damage hdd.
The temperature of the hdd was often 50 celcius degree and I left it running for days, weeks, ..., because it couldnt wake up from suspension probably due to outdated Ubuntu and packages.
 
@Ben Modern filesystems are good at handling such things. I use ext4 and my machine regularly crashes, I'm sorry to say. I've never noticed any corruption.
There might be better choices for FSs. I've heard good things about ZFS. But it's not part of the main kernel, and there are some license issues.
But I don't know if ZFS is actually better than ext4.
 
If make a chroot will it succeed to run vs code remote?
 
@EnthusiastiC ah, why do you want to run VS Code remotely on your old server?
 
9:54 AM
Simply, I found it easier to code
 
Yes, but why do you want to run it remotely on your old server?
 
If I want to code remotely with VS code then that should be the case
coding remotely because...
I have to use the high computing performance advantage
 
@EnthusiastiC for coding? Can’t you code locally and run your code remotely? VS Code has all sorts of features to support that
 
VS as in Visual Studio? That's an MS thing.
 
indeed.
The repetitive task is
to run on bash
./bashscript inputfile
bashscript as the name suggests uses bash shell to execute the program through piping the inputfile to the main executable program which requires the remote machine to compute some data
not lot of coding needed here.
I don't know how such calling the remote executable from VS client side enables to retrieve the desired data from the remote machine
 
10:17 AM
you can also just run ssh inside the VS Code terminal
 
using only terminal VS is useless at this point
 
try it and see
you can also open remote files
 
Once upon a time I think Python's os had popen3, which still lives on in other things with similar names. But that function seems to be have been obsoleted by the subprocess library.
Though I don't understand why it was necessary to remove it.
 
10:45 AM
With reference to this comment:
I had to add posix.close(r) and posix.close(e) after the loops to drain them in ps.pipe_simple(). Otherwise got 'too many open files' after 500 calls to this on linux. — robm Apr 5 '17 at 7:32
The Valgrind documentation suggests that it reports leaked file descriptors.
Just wondering if anyone has used it.
 
10:58 AM
@FaheemMitha it is MS, but it's cross-platform, and open-source github.com/Microsoft/vscode
 
@AndrasDeak I was not aware of that.
 
11:10 AM
It turns out I have quite a few C books, all purchased a long time ago, and which I had mostly forgotten out. Just pulled them all out.
 
Ben
Greetings once more!
 
Ben
11:27 AM
To so many beautiful people here. What are your top 2 favorite Linux distributions?
or top 2 most useful to your life and work, not necessarily best in your opinion?
 
@Ben I've used Debian since summer 2001.
Since then I've not really used anything else. You might find the "Getting to know you" thread on U&L Meta of interest.
 
Ben
by favorite, I mean the best to your knowledge, not necessarily by experience
 
 
1 hour later…
Ben
12:38 PM
The most popular Linux distribution is probably Ubuntu, in life and work, right? I guess that my procrastination of updating and upgrading the system and packages caused my system crashes and my hdd failure.
So I had been thinking about Debian as a better replacement of Ubuntu.
Now I feel in love with NixOS
 
Why do you keep blaming software for a hardware failure? HDDs fail, the only question is when.
 
Ben
I have rescued two computers from trash. So I was wondering if I shall install NixOS on both, or maybe do something that complement each other.
 
And what you do about it (i.e. backup often)
 
Ben
I like to know what you gentle persons think of the best distributions.
 
To give a vaguely useful answer we’d have to know what you want to do with your computer.
 
12:53 PM
Darn, I was going to suggest the popcon results :>
unfortunately, both Debian and NixOS will have upgrades to apply
 
@StephenKitt @FaheemMitha NULL could also just be defined as a raw zero, which would be an int. It'd work as a null pointer in any context where the compiler knows it's supposed to be a pointer, but like Michael said, since execl*() are varargs functions, it can't know that. So we get the issue where execl(..., NULL) could be the same as execl(..., 0), which could cause an issue when the caller passes an int and the function expects a pointer. Hence the cast in this particular case.
 
@ilkkachu yes, and it is a raw 0 in C++
 
yeah, the C vs. C++ difference too...
 
 
1 hour later…
Ben
2:00 PM
@StephenKitt general purposes. I am not good at timely updating and upgrading system and packages.
I was more wondering what you people know/think/hear are the best
 
There's no such thing as best. I don't know of any "bad" distributions unless you take into account silly things like Suicide Linux or Hannah Montana Linux.
So "best" simply means "this is the one I, personally, enjoy using".
 
I agree 100%. For most users the best distribution is the one that they are familiar with, or if they’re not particularly familiar with one, the one with which they can easily get help.
 
Ditto; if I was starting over, I'd look for one that was (1) well-maintained (had a history of regular updates), and (2) made sense to me from system administration & maintenance standpoint
 
2:23 PM
...and I am afraid there is no distribution that can be called "best" when the requirement is not to need (somewhat timely) updates (especially from the security perspective). There are, though, some that tend to perform terribly in that case - e.g. rolling release distributions.
 
@fra-san there are quite a few distros which apply (or can be configured to apply) security updates automatically, which helps a bit.
 
@fra-san terribly? Why?
Oh because they're constantly updated. Right. Sorry, not used to thinking of that as bad :)
 
@StephenKitt Yes, and I agree it's an important thing to mention. I was implying that setting up automatic updates is a way of... addressing the need for updating :-) (contrasted to being unwilling to address the issue at all).
 
@fra-san indeed. I suspect that readers like Ben might not be aware that automatic updates are even possible!
 
2:41 PM
@terdon I don't think that's bad too. But it is hard (or impossible?) to support upgrading from an arbitrary point in time. It's reasonable to expect (and is also what I have experienced) that recovering a significantly outdated system would require a significant level of expertise.
 
Which reminds me, I should run pcaman -Suy!
 
@StephenKitt Right. It takes (and took me, for one) some time to get accustomed to the elements (maintainers, repositories, package management, task scheduling...) that make the concept feel natural.
 
2:59 PM
@terdon what does pacman -Sorry do?
So of course Aptitude has a minesweeper built-in, I expect pacman has an appropriate game too ;-)
 
No -o option :-(
 
this is close though:
$ sudo pacman -Srry
error: failed to initialize alpm library:
(root: ry, dbpath: ry/var/lib/pacman/)
could not find or read directory
 
3:49 PM
@ilkkachu By a "raw zero" you just mean the integer 0, right?
 
@FaheemMitha yeah.
 
@Ben Ubuntu is probably among the easiest things to just start up and get running.
And it has a huge user community. It even has a separate site on SE.
At least some of time I got the feeling that the people behind the project were trying to position it as a competitor to MS Windows. Not direct competition, perhaps. More something people fed up with MS Win could relatively easily transition to.
But I haven't made any effort to track the project in a long time.
This isn't a recommendation so much as an observation.
 
4:24 PM
I'm looking (again) at stackoverflow.com/a/16515126/350713
As an exercise, I'm trying to translate the first function to C.
I don't see why the poster doesn't close r3 like he did r2.
He has:
posix.close(r2)
Shouldn't he have:
posix.close(r3)
as well, by similar logic?
As I understand it, then the write end of the pipe is with the child. And the read end is with the parent.
That seems to be to apply to standard error as much as standard output.
I was wondering if current versions of C support this kind of idiom. They didn't use to.
int r1, w1 = fd1;
Where int fd1[2];
I.e. fd1 is a C array of 2 values.
 
4:40 PM
@FaheemMitha maybe the SO chat server is a better place for discussing SO posts.
 
@terdon It's about POSIX, so I think on topic here.
 
@FaheemMitha It's chat, there are no clear "on topic" or "off topic" things. But you basically seem to be talking to yourself about a post on another site using a language most of the people here have no experience with (lua). Surely it would be more helpful for you to discuss this in a place where programmers hang out.
In any case, asking why someone's code didn't close a file descriptor sounds like something you should be asking the poster, or posting a question on SO about.
 
@terdon I'm not "talking to myself". I've been discussing this with people in the chat sporadically over the last couple of days. And Lua Posix calls are just a thin wrapper for the corresponding C system calls. The conversation is mostly about the Posix calls. Lua is an unimportant detail. I'm just referencing the post because it's close to something I'm trying to do.
There might be better matches out there, but I haven't found one, and it's probably worth doing a lot of searching, because the basic structure is quite simple.
 
OK, as you wish.
 
5:12 PM
Probably not worth. Sorry.
 
 
1 hour later…
6:18 PM
for what it's worth I don't think there's a lua chatroom on chat.SO
 
 
1 hour later…
7:26 PM
This is the current version of my C program: gist.github.com/44781cbe8a9c655a0d67f3c511405a1e
 
(void *)0 is not guaranteed to be a universal null pointer, so it's not linguistically an appropriate definition of NULL
the null-pointer constant is 0
 
@AndrasDeak As far as I know there isn't. There's a #lua on freenode. Or there used to be. Since freenode's meltdown, it's probably moved.
 
Again, in practice, it's going to be fine in concrete Linux+glibc+x86(_64)? situations, but it's language-lawyer not ok
 
There might be one on the IRC server that Debian uses.
@MichaelHomer Is (void *)NULL the best choice?
Anyway, there is one thing I'm not totally clear on with my program.
 
@FaheemMitha The correct choice in your usage has always been the one it told you to use
There is a #lua on Libera, yes
 
7:30 PM
Without the _exit(EXIT_FAILURE); line, the child exit code returns 0. I'm guessing that is what it was initialized as. With that line, it returns the correct exit code.
I'm guessing that the exit is required for waitpid to be properly initialized, but I'm not completely clear why.
Correction: what waitpid does isn't strictly relevant.
 
Your program returns 0 from main
 
Sorry, I take that last line back.
 
@FaheemMitha without the call to _exit, it runs off the end of popen3(), which returns to main, which returns 0, which becomes the process exit code.
 
@MichaelHomer Oh, yes, so it does. I need to take that off.
@ToxicFrog And without the return 0 bit? Let me check.
OK, I took out the return in main, which I don't think is necessary.
Without that, I still get 0 without the _exit, and 1 with (which is the correct value).
Not saying there is anything wrong with that. Just not clear why it's happening.
 
Your main function needs to return something.
 
7:34 PM
@MichaelHomer Sure. It returns whatever popen3 returns.
 
It probably returns whatever detritus is on the stack
It does not return what popen3 returns
 
Um. Maybe that doesn't work, since popen3 currently returns void.
 
(which is nothing)
 
@MichaelHomer Right.
So should I leave that return 0 in, then?
 
I mean, it's mandatory
 
7:36 PM
Oh.
 
So yes, but I don't understand why you took it out
You already have a working program? I don't know what it's for, but it sounded like it was done
 
I thought it was unnecessary.
@MichaelHomer Yes, but there is that bit I'm not clear on. See above.
And there is more stuff I need to add, I think.
If the parent goes off the rails, I want the stdout from that, for example.
 
If your program doesn't exit early it runs to the end, yes
 
@MichaelHomer And then the parent doesn't receive the exit code?
 
9 mins ago, by ToxicFrog
@FaheemMitha without the call to _exit, it runs off the end of popen3(), which returns to main, which returns 0, which becomes the process exit code.
 
7:42 PM
@MichaelHomer Yes, I read that. Didn't understand it, though. So with the call to _exit, the process exit code becomes that corresponding to that execlp call, but not otherwise?
 
It becomes EXIT_FAILURE like you told it
 
BTW, does all of this stuff belong to POSIX? Stevens doesn't seem to talk much about POSIX.
@MichaelHomer Ah. I guess I need to look up EXIT_FAILURE. Hold on.
 
It's presumably 1
 
I found some places saying it's 8.
I want the exit value of the process run by execlp, in case that isn't clear.
Anyway, probably time to stop for today. It's late.
 
You've already observed that it's 1, so
@FaheemMitha this is total nonsense
 
7:47 PM
@MichaelHomer Why is it total nonsense?
 
THERE IS NO EXIT VALUE OF THE PROCESS RUN BY EXECLP, THAT"S WHAT IT MEANS FOR EXEC TO FAIL
If you reached the exit line, exec has failed
 
@MichaelHomer OK, maybe not exit value. The return value. The thing you get on the shell.
 
I never learn, do I
 
I.e. echo $?
 
_exit(127);
 
Ben
8:01 PM
I was wondering what hdd might be cheap and reliable for mirroring my failed 1TB hdd? Anyone can link me to some product webpages on ebay, or other frugal websites?
Might data recovery service want me to send them my data in a hdd? Then do I need two hdds, one for them and one for my future backup?
Is there some website for buying second handed and maybe unused hardware?
less costly than buying new?
Thanks in advance, gentlepersons!
 
@MichaelHomer it's a valid definition for NULL in C, also the one gcc/glibc uses on the one system I looked at
 
Ben
Which way shall I go?
First dd my 1TB failed hdd to a 1TB .iso file, and then run some forensics tool on the .iso file. What capacity of another hdd do I need for creating a .iso mirror file?
Or like what @StephenKitt wrote, directly run ddrescue on the failed hdd, and it will generate lots of logs when mirroring the failed hdd, so I need another 2TB hdd.
 
8:18 PM
@FaheemMitha when I looked at that program (just now, about 45 mins later than the link), I saw the line execlp("lsx", "lsx", "-la", "zarko.tex", (char *)NULL);. Do you have a program called lsx, then? What does it do?
@FaheemMitha, I might suggest getting rid of the pipeworks messing with stderr, and then checking the return value of the execlp() call, and errno after it
 
8:59 PM
@ilkkachu No, it isn't, because void * is not compatible with function pointers
(in the specification, rather than in practice)
On probably-most systems all pointers are the same size and compilers allow it, but in language-lawyer terms you can't cast between function pointers and other pointers
That's what it means by "implementation-defined constant" - your implementation will provide something, but 0 as a pointer type is always a correct null in any C
 
 
2 hours later…
Ben
10:35 PM
@MichaelHomer Do you have recommendation on backup devices for me?
 
Truthfully I don't have any non-network backups
I have previously, but not for a while
Maybe I should
 
10:51 PM
@Ben As previously said: 1) do nothing with your failed HDD if you are going to hand it to someone else for attempting data recovery; 2) using dd on your failed HDD is unlikely to work, and chances are it will make things worse (depending on how/why the disk is failing); using a data recovery tool to copy the content of your failing HDD to a bigger one seems the only sensible option (unless you are doing (1)).
 
Ben
11:08 PM
Thanks.
> using a data recovery tool to copy the content of your failing HDD to a bigger one seems the only sensible option
What data recovery tool do you know is good/best?
With such a tool, will it generate bit-level or file-level results? (like dd or like resync)?
 
11:18 PM
@Ben As I said earlier, both ddrescue or dd_rescue are often mentioned, but I personally know none of them, sorry.
 
Ben
11:28 PM
Thanks. I will look into ddrescue. I didn't know the other. If any other data recovery tool, I'd appreciate letting me know.
I am not sure what a data recovery service can do. Can they be more powerful than ddrescue? I also appreciate letting me know any capable data recovery service
 
They may e.g. have specialised disk imaging hardware
It's not certain they would get any better result than reading it live
Most of the time I'd say it's not worth it for an individual
 
Ben
What does "reading it live" mean? What is it opposed to?
"disk imaging hardware" does mirroring only creating a copy of the failed hdd?, and then some other tool does analysis and recovery on the copy of the failed hdd?
"reading it live" means performing analysis and recovery on the failed hdd directly?
which may further damage the failed hdd?
Does ddrescue read it live?
@Kusalananda I just learned it on meta. Life is so fragile. Will continue to remember the fun time
and his helps
He often tried to help those being marginalized in the community.
 

« first day (4030 days earlier)      last day (212 days later) »