Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6967737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:21:37+00:00 2026-05-27T16:21:37+00:00

I modified GNU tee to cycletee Source Code (You can download the binary from

  • 0

I modified GNU tee to cycletee Source Code (You can download the binary from https://github.com/vls/cycletee/tree/master/bin)

What it does can be explained by the following example:

seq 10 | cycletee 1.txt 2.txt 3.txt
cat 1.txt // prints 1, 4, 7, 10
cat 2.txt // prints 2, 5, 8
cat 3.txt // prints 3, 6, 9

Then there is a all.tgz (See Appendix for building script)

all.tgz has three text file and totally 9000000 lines.

Everything is fine. Like:

seq 10000000 | ./cycletee 1.txt 2.txt 3.txt

zcat all.tgz | tee 1.txt > /dev/null

zcat all.tgz | tail // got 9000000 at the last line

except calling:

zcat all.tgz | ./cycletee 1.txt 2.txt 3.txt

when it reads the No.3000000 line, it exits.

strace it I got this message and it exited:

_llseek(2, 0, 0xffbec3d0, SEEK_CUR)     = -1 ESPIPE (Illegal seek)

Question

  • Anyone can point out the problem of my source code?

  • Any debugging technique to figure out the problem will be appreciated. I don’t know how to use gdb in this situation.

Appendix

  • all.tgz can be built by this Python sciprt https://gist.github.com/1500742

  • Environment: Ubuntu 10.04 32bit, CentOS 5.4 64bit

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:21:38+00:00Added an answer on May 27, 2026 at 4:21 pm

    From the source:

    read:
        buffer[0] = '\0';
        ptr = fgets(buffer, (int) sizeof buffer, stdin);
        if(NULL == ptr) {
            if(ferror(stdin)) {
                error (0, errno, "%s", _("standard input"));
                ok = false;
            }
            flag_break = true;
            break;
        }
        bytes_read = strlen(buffer);
    
    
          if (bytes_read < 0 && errno == EINTR)
          {
              flag_continue = true;
              backup_i = i;
              break;
          }
          if (bytes_read <= 0) {
              flag_break = true;
              break;
          }
    
        if (descriptors[0]
                && fwrite(buffer, bytes_read, 1, descriptors[0]) != 1)
                {
                    error (0, errno, "%s", files[0]);
                    descriptors[0] = NULL;
                    ok = false;
                }
     ...
    

    I don’t think this will work on binary input (input that contains NULs).
    [ Given the signedness of bytes_read, I have the strong suspicion that fread() has been replaced by fgets() + strlen(); ] This may or may not be the cause of the PIPE error, but it looks very wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When trying to use a modified version of the Lisp snippet from the GNU
From http://fullthrottledevelopment.com/php-nonce-library#download , there is a PHP nonce library, but there are a few
I modified the source code of memcached-1.4.7, but I got stuck when I tried
I modified the code here (http://www.w3schools.com/PHP/php_ajax_database.asp) to update and display my database after an
I modified this code from somewhere but I am not sure if I am
For the purposes of code review, after an existing source file is modified, we
I'm trying to download some remote pages. In the source code there is a
I had to modify some open source code to use in a C project.
I modified a very simple php page on my server: <?php header(Location:http://www.google.com); ?> and
I modified my data source in my LINQ-to-SQL class (by the old delete and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.