Logging in shared file


 
Thread Tools Search this Thread
Top Forums Programming Logging in shared file
# 8  
Old 10-03-2013
I've explored that there are big difference between
Code:
{         va_start( args, format );      length = vsnprintf( buffer, BUF_LEN, format, args );
    
    if (length >= BUF_LEN )
    { 
     expandBuffer(buffer, length + 1);  
     length = vsnprintf(buffer, length + 1, format, args );     }         va_end( args ); }

and
Code:
{    
    va_list args2;     va_start( args, format );     va_copy(args2,args);
    length = vsnprintf( buffer, BUF_LEN, format, args );
    
    if (length >= BUF_LEN )
    { 
     expandBuffer(buffer, length + 1);  
     length = vsnprintf(buffer, length + 1, format, args2 );     }         va_end( args ); }

The first variant doesn't work if the second vsnprintf is called. vsnprintf spoil the args.
# 9  
Old 10-05-2013
What platform and O/S are you running on? Because I don't think that should happen.

That sounds like your stack is getting corrupted, and that's not good.
# 10  
Old 10-14-2013
Linux Red Hat. I've build it also on openvms alpha 8.3. May be I can check it on a small example, where a stack corruption will be practically impossible.

---------- Post updated at 05:25 AM ---------- Previous update was at 04:44 AM ----------

So the experiment:
1. Without copying
main.c
Code:
void vprintf2x(char * format, va_list args)
{
  vprintf(format, args);
  vprintf(format, args);
}

void printf2x(char * format, ...)
{
  va_list args;
  va_start(args, format);
  vprintf2x(format, args);
  va_end(args);
}


int main()
{
  printf2x("%s - %s", "123", "321\n");
  return 0;
}

Result:
$ ./a.out
123 - 321
Segmentation fault


2. With copying
main.c
Code:
#include <stdio.h>
#include <stdarg.h>

void vprintf2x(char * format, va_list args)
{
  va_list args2;
  va_copy(args2, args);
  vprintf(format, args);
  vprintf(format, args2);
  va_end(args2);
}

void printf2x(char * format, ...)
{
  va_list args;
  va_start(args, format);
  vprintf2x(format, args);
  va_end(args);
}


int main()
{
  printf2x("%s - %s", "123", "321\n");
  return 0;
}

Result:
$ ./a.out
123 - 321
123 - 321
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Cannot open shared object file: No such file or directory

Hi, While running tcpdump command on my Fedora 16 machine I am get shared library issue. # tcpdump tcpdump: error while loading shared libraries: libcrypto.so.6: cannot open shared object file: No such file or directory # which tcpdump /usr/software/sbin/tcpdump I have tried... (3 Replies)
Discussion started by: muzaffar.k
3 Replies

2. Linux

Syslog not logging successful logging while unlocking server's console

When unlocking a Linux server's console there's no event indicating successful logging Is there a way I can fix this ? I have the following in my rsyslog.conf auth.info /var/log/secure authpriv.info /var/log/secure (1 Reply)
Discussion started by: walterthered
1 Replies

3. Shell Programming and Scripting

Logging success event into file

Hi, I've the following code to log the errors any after the command is executed. # Ksh 88 Version log_path=/home/etc/fls/fls_log.log del_path=/home/etc/fls/to_day rm $del_path/* >> $log_path 2>&1 But I even want to log if the rm command is success without any error along with... (1 Reply)
Discussion started by: smile689
1 Replies

4. Programming

Shared library with acces to shared memory.

Hello. I am new to this forum and I would like to ask for advice about low level POSIX programming. I have to implement a POSIX compliant C shared library. A file will have some variables and the shared library will have some functions which need those variables. There is one special... (5 Replies)
Discussion started by: iamjag
5 Replies

5. Red Hat

libodbc.so.1: cannot open shared object file: No such file or directory

We are trying to install third party software on this unix server... Here is the error message we are getting... error while loading shared libraries: libodbc.so.1: cannot open shared object file: No such file or directory It seems like odbc driver is not installed... >rpm -q unixODBC... (1 Reply)
Discussion started by: govindts
1 Replies

6. Shell Programming and Scripting

logging to file

I am trying to figure a way to have a log file and still keep the output in the terminal in a script. The example below logs to a file nicely but i still want the output in the terminal as well #!/bin/bash #Create a log exec >> /path/to/my/logfile echo "hello world" Any help would be... (3 Replies)
Discussion started by: dave100
3 Replies

7. Programming

libRmath.so: cannot open shared object file: No such file or directory

% locate Rmath /m/backup/backup/lib/R/include/Rmath.h /usr/lib/R/include/Rmath.h % gcc -g -o stand stand.c -I/usr/lib/R/include/ -lRmath -lm % ./stand ./stand: error while loading shared libraries: libRmath.so: cannot open shared object file: No such file or directory What's the trouble... (6 Replies)
Discussion started by: cdbug
6 Replies

8. Programming

Shared memory for shared library

I am writing a shared library in Linux (but compatible with other UNIXes) and I want to allow multiple instances to share a piece of memory -- 1 byte is enough. What's the "best" way to do this? I want to optimize for speed and portability. Obviously, I'll have to worry about mutual exclusion. (0 Replies)
Discussion started by: otheus
0 Replies

9. UNIX for Dummies Questions & Answers

Logging all console activity to a file - how?

Hi all, Well I've had a bit more experience with Unix-like environments since my last post, now that I have started working on my website in earnest and am doing much of the file manipulation via the command line through SSH. The thing is, I want to be able to log all console activity,... (4 Replies)
Discussion started by: patwa
4 Replies

10. Programming

Shared memory in shared library

I need to create a shared library to access an in memory DB. The DB is not huge, but big enough to make it cumbersome to carry around in every single process using the shared library. Luckily, it is pretty static information, so I don't need to worry much about synchronizing the data between... (12 Replies)
Discussion started by: DreamWarrior
12 Replies
Login or Register to Ask a Question