Opened 12 years ago

Closed 12 years ago

#578 closed defect (fixed)

bug in libmondo-devices.c

Reported by: victor gattegno Owned by: Bruno Cornec
Priority: high Milestone: 3.0.1
Component: mondo Version: 3.0.0
Severity: normal Keywords: CD DVD
Cc:

Description

This concerns these lines in libmondo-devices.c

Line 916 : ("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1")
Line 921 : ("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1")

If I execute it manually on a RHEL 6 machine, I get an error:

# cdrecord -scanbus 2> /dev/null | grep \") '\" 
-bash: syntax error near unexpected token `)'

I found this solution:

# cdrecord -scanbus 2> /dev/null | grep \)\ \'  
      0,0,0     0) 'TEAC    ' 'DV-W28E-RW      ' 'G.B2' Removable CD-ROM

Also, line 921, there is a "grep DVD"

I guess that it should be a "grep CD".

Otherwise, on my RHEL 6 results, I don't see the utility of the grep -n \"\"

# cdrecord -scanbus | grep \)\ \' | grep -n \"\"
#

Because there is no " in the results of dvdrecord nor in the results of cdrecord.

# dvdrecord -scanbus
scsibus0:
        0,0,0     0) 'TEAC    ' 'DV-W28E-RW      ' 'G.B2' Removable CD-ROM
        0,1,0     1) *
        0,2,0     2) *
        0,3,0     3) *
        0,4,0     4) *
        0,5,0     5) *
        0,6,0     6) *
        0,7,0     7) *
# cdrecord -scanbus   
scsibus0:
        0,0,0     0) 'TEAC    ' 'DV-W28E-RW      ' 'G.B2' Removable CD-ROM
        0,1,0     1) *
        0,2,0     2) *
        0,3,0     3) *
        0,4,0     4) *
        0,5,0     5) *
        0,6,0     6) *
        0,7,0     7) *

Anyway cdrecord and dvdrecord are a link to wodim

# ls -l /usr/bin/dvdrecord
lrwxrwxrwx. 1 root root 36 Oct 11 16:23 /usr/bin/dvdrecord -> /etc/alternatives/cdrecord-dvdrecord
# ls -l /usr/bin/cdrecord 
lrwxrwxrwx. 1 root root 26 Oct 11 16:23 /usr/bin/cdrecord -> /etc/alternatives/cdrecord
# ls -l /etc/alternatives/cdrecord-dvdrecord
lrwxrwxrwx. 1 root root 14 Oct 11 16:23 /etc/alternatives/cdrecord-dvdrecord -> /usr/bin/wodim
# ls -l /etc/alternatives/cdrecord
lrwxrwxrwx. 1 root root 14 Oct 11 16:23 /etc/alternatives/cdrecord -> /usr/bin/wodim

As there is no : delimitator in the results, I suggest

# cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep CD | cut -d' ' -f1 
        0,0,0

And the same for DVD, I cannot test but it should be

# dvdrecord -scanbus 2> /dev/null | grep \)\ \' | grep DVD | cut -d' ' -f1

Now, for blu-ray, maybe another test will be needed too.

Attachments (1)

libmondo-devices.c.gz (23.2 KB ) - added by victor gattegno 12 years ago.
libmondo-devices.c patched to get a successfull detection

Download all attachments as: .zip

Change History (14)

comment:1 by victor gattegno, 12 years ago

On Ubuntu 11.10 64 bits

There's no dvdrecord, but cdrecord is also a link to wodim.

The "cdrecord -scanbus" result is the same as under RHEL 6.

comment:2 by victor gattegno, 12 years ago

This is the result of dvdrecord/cdrecord for a Blu-ray device :

scsibus0:
        0,0,0     0) 'PIONEER ' 'BD-RW   BDR-206D' '1.04' Removable CD-ROM
        0,1,0     1) *
        0,2,0     2) *
        0,3,0     3) *
        0,4,0     4) *
        0,5,0     5) *
        0,6,0     6) *
        0,7,0     7) *

comment:3 by victor gattegno, 12 years ago

On Ubuntu 11.10 this is the result of cdrecord for a DVD device :

...
scsibus1:
	1,0,0	100) 'PLEXTOR ' 'DVDR   PX-880SA ' '1.10' Removable CD-ROM
	1,1,0	101) *
        ...

comment:4 by victor gattegno, 12 years ago

This one is not good :

# cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep CD | cut -d' ' -f1
    1,0,0    100)

Finally the solution is (as tabulation is the delimiter) :

# cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep CD | cut -f2
1,0,0

It works on RHEL 6 and on Ubuntu 11.10.

comment:5 by victor gattegno, 12 years ago

I would modify libmondo-devices.c lines 915-924 as this :

	sprintf(tmp, "%s", call_program_and_get_last_line_of_output
			("dvdrecord -scanbus 2> /dev/null | grep \)\ \' | grep DVD | cut -f2")
		);
	log_msg(5, "tmp = '%s'", tmp);
	if (!tmp[0])
		sprintf(tmp, "%s", call_program_and_get_last_line_of_output
				("cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep CD | cut -f2")
			);
	if (tmp[0]) {
		devno = atoi(tmp);

by victor gattegno, 12 years ago

Attachment: libmondo-devices.c.gz added

libmondo-devices.c patched to get a successfull detection

comment:6 by Bruno Cornec, 12 years ago

Status: newassigned

the grep -n could be used for other stuff in the code, so I prefered to keep it.

However, I changed the regexp used later and all the test cases seem now to pass.

So I pushed rev [2933] for you to test as well as pkg for RHEL 5, 6 and Ubuntu 11.10 under ftp://ftp.mondorescue.org/test

comment:7 by victor gattegno, 12 years ago

It still doesn't work, because the beginning of lines 918 and 923 are not adequate :

# dvdrecord -scanbus 2> /dev/null | grep \") 
-bash: syntax error near unexpected token `)'

It's why I proposed this modification:

# dvdrecord -scanbus 2> /dev/null | grep \)\ \'
        0,0,0     0) 'TEAC    ' 'DV-W28E-RW      ' 'G.B2' Removable CD-ROM

Also:

  1. there is no " in the result of "# dvdrecord -scanbus" so why the : grep -n \"\" ??
  2. the separator is not ":" so "cut -d':' -f1" can't work neither

It's why I propose this final modification:

# cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -E '[D|C][V|D]' | cut -f2  
0,0,0

comment:8 by victor gattegno, 12 years ago

I tested it on RHEL 6 and on Ubuntu 11.10 and it works well on both.

Maybe the " appeared in the result of older versions of cdrecord ?

in reply to:  7 comment:9 by Bruno Cornec, 12 years ago

Replying to vicgat:

It still doesn't work, because the beginning of lines 918 and 923 are not adequate :

# dvdrecord -scanbus 2> /dev/null | grep \") 
-bash: syntax error near unexpected token `)'

On my machine:

$ cdrecord -scanbus 2> /dev/null | grep ") '"
        5,0,0   500) '_NEC    ' 'DVD_RW ND-3500AG' '2.1A' Removable CD-ROM
        5,1,0   501) 'HL-DT-ST' 'CD-ROM GCR-8480B' '2.05' Removable CD-ROM

That's true if you pass it like that at CLI. But this is called from C thus the " is prepended with a \ to not be interpreted and passed to the shell unchanged. Do you mean this is not working from the C call ?

It's why I proposed this modification:

# dvdrecord -scanbus 2> /dev/null | grep \)\ \'
        0,0,0     0) 'TEAC    ' 'DV-W28E-RW      ' 'G.B2' Removable CD-ROM

As I'm not testing this very often, I changed it to your regexp which is identical.

Also:

  1. there is no " in the result of "# dvdrecord -scanbus" so why the : grep -n \"\" ??

For that:

[bruno@victoria2 3.0]$ cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n ""
1:      5,0,0   500) '_NEC    ' 'DVD_RW ND-3500AG' '2.1A' Removable CD-ROM
2:      5,1,0   501) 'HL-DT-ST' 'CD-ROM GCR-8480B' '2.05' Removable CD-ROM
[bruno@victoria2 3.0]$ cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n "" | grep -E '[D|C][V|D]' | cut -d':' -f1
1
2
  1. the separator is not ":" so "cut -d':' -f1" can't work neither

The ":" appears due to the -n of grep ! But again the "" may cause an issue, even if prepended with \ Is that what you mean ?

I have changed them to ' which should not be modified then.

Look at rev [2941]. I will remake packages ASAP.

comment:10 by victor gattegno, 12 years ago

You are right, Bruno.

Rev 2941 seems ok to me.

comment:11 by victor gattegno, 12 years ago

One last modif, maybe it should be better to have :

grep -n \'\'

instead of :

grep -n ''

I installed rev 2941 and I will already test it, then I will see if this last modif is necessary or not.

comment:12 by Bruno Cornec, 12 years ago

Hello any feedback on this context ?

comment:13 by Bruno Cornec, 12 years ago

Milestone: 3.0.23.0.1
Resolution: fixed
Status: assignedclosed

Closing for now as I think this has been fixed. Please reopen if not the case.

Note: See TracTickets for help on using tickets.