+static int popen_pclose_checked(const char *command)
+{
+FILE *f;
+char buf[SYSTEM_CHECKED_BUFFER_SIZE];
+size_t got;
+
+ if (!(f=popen(command,"r")))
+ fatal("Error opening spawned command \"%s\": %m",command);
+ setlinebuf(f);
+ while ((got=fread(buf,1,sizeof(buf)-1,f))) {
+char *s,*s_next;
+
+ assert(got<sizeof(buf));
+ buf[got]=0;
+ for (s=buf;*s;s=s_next) {
+ if ((s_next=strchr(s,'\n'))) {
+ *s_next++=0;
+ error("Error line of spawned \"%s\": %s",command,s);
+ }
+ else {
+ s_next=s+strlen(s);
+ error("Error line of spawned \"%s\" too long, string cut: %s",command,s);
+ }
+ }
+ }
+ if (ferror(f))
+ fatal("Error reading output of spawned \"%s\"",command);
+ if (!feof(f))
+ fatal("Error reaching end-of-file of messages of spawned \"%s\"",command);
+ return pclose(f);
+}
+